Skip to content

Commit c10010e

Browse files
feat(db): Support passing db connection as separate env vars (#545)
1 parent d24de79 commit c10010e

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- Added support for passing db connection url as seperate `DATABASE_HOST`, `DATABASE_USERNAME`, `DATABASE_PASSWORD`, `DATABASE_NAME`, and `DATABASE_ARGS` env vars. [#545](https://github.com/sourcebot-dev/sourcebot/pull/545)
12+
1013
## [4.7.3] - 2025-09-29
1114

1215
### Fixed

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ ENV DATA_DIR=/data
185185
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
186186
ENV DATABASE_DATA_DIR=$DATA_CACHE_DIR/db
187187
ENV REDIS_DATA_DIR=$DATA_CACHE_DIR/redis
188-
ENV DATABASE_URL="postgresql://postgres@localhost:5432/sourcebot"
189188
ENV REDIS_URL="redis://localhost:6379"
190189
ENV SRC_TENANT_ENFORCEMENT_MODE=strict
191190
ENV SOURCEBOT_PUBLIC_KEY_PATH=/app/public.pem

docs/docs/configuration/environment-variables.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The following environment variables allow you to configure your Sourcebot deploy
1919
| `DATA_CACHE_DIR` | `$DATA_DIR/.sourcebot` | <p>The root data directory in which all data written to disk by Sourcebot will be located.</p> |
2020
| `DATA_DIR` | `/data` | <p>The directory within the container to store all persistent data. Typically, this directory will be volume mapped such that data is persisted across container restarts (e.g., `docker run -v $(pwd):/data`)</p> |
2121
| `DATABASE_DATA_DIR` | `$DATA_CACHE_DIR/db` | <p>The data directory for the default Postgres database.</p> |
22-
| `DATABASE_URL` | `postgresql://postgres@ localhost:5432/sourcebot` | <p>Connection string of your Postgres database. By default, a Postgres database is automatically provisioned at startup within the container.</p><p>If you'd like to use a non-default schema, you can provide it as a parameter in the database url </p> |
22+
| `DATABASE_URL` | `postgresql://postgres@ localhost:5432/sourcebot` | <p>Connection string of your Postgres database. By default, a Postgres database is automatically provisioned at startup within the container.</p><p>If you'd like to use a non-default schema, you can provide it as a parameter in the database url.</p><p>You can also use `DATABASE_HOST`, `DATABASE_USERNAME`, `DATABASE_PASSWORD`, `DATABASE_NAME`, and `DATABASE_ARGS` to construct the database url.</p> |
2323
| `EMAIL_FROM_ADDRESS` | `-` | <p>The email address that transactional emails will be sent from. See [this doc](/docs/configuration/transactional-emails) for more info.</p> |
2424
| `FORCE_ENABLE_ANONYMOUS_ACCESS` | `false` | <p>When enabled, [anonymous access](/docs/configuration/auth/access-settings#anonymous-access) to the organization will always be enabled</p>
2525
| `REDIS_DATA_DIR` | `$DATA_CACHE_DIR/redis` | <p>The data directory for the default Redis instance.</p> |

entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#!/bin/sh
22
set -e
33

4+
# Check if DATABASE_URL is not set
5+
if [ -z "$DATABASE_URL" ]; then
6+
# Check if the individual database variables are set and construct the URL
7+
if [ -n "$DATABASE_HOST" ] && [ -n "$DATABASE_USERNAME" ] && [ -n "$DATABASE_PASSWORD" ] && [ -n "$DATABASE_NAME" ]; then
8+
DATABASE_URL="postgresql://${DATABASE_USERNAME}:${DATABASE_PASSWORD}@${DATABASE_HOST}/${DATABASE_NAME}"
9+
10+
if [ -n "$DATABASE_ARGS" ]; then
11+
DATABASE_URL="${DATABASE_URL}?$DATABASE_ARGS"
12+
fi
13+
14+
export DATABASE_URL
15+
else
16+
# Otherwise, fallback to a default value
17+
DATABASE_URL="postgresql://postgres@localhost:5432/sourcebot"
18+
export DATABASE_URL
19+
fi
20+
fi
21+
422
if [ "$DATABASE_URL" = "postgresql://postgres@localhost:5432/sourcebot" ]; then
523
DATABASE_EMBEDDED="true"
624
fi

0 commit comments

Comments
 (0)