Skip to content

Commit 1908051

Browse files
feat(web,worker): Environment overrides (#597)
1 parent 5fde901 commit 1908051

File tree

140 files changed

+1264
-809
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+1264
-809
lines changed

.env.development

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ SOURCEBOT_TELEMETRY_DISABLED=true # Disables telemetry collection
8484
# NEXT_PUBLIC_SOURCEBOT_VERSION=
8585

8686
# CONFIG_MAX_REPOS_NO_TOKEN=
87-
# NODE_ENV=
87+
NODE_ENV=development
8888
# SOURCEBOT_TENANCY_MODE=single
8989

9090
# NEXT_PUBLIC_SOURCEBOT_CLOUD_ENVIRONMENT=

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
## Added
1111
- [Experimental][Sourcebot EE] Added GitLab permission syncing. [#585](https://github.com/sourcebot-dev/sourcebot/pull/585)
1212
- [Sourcebot EE] Added external identity provider config and support for multiple accounts. [#595](https://github.com/sourcebot-dev/sourcebot/pull/595)
13+
- Added ability to configure environment variables from the config. [#597](https://github.com/sourcebot-dev/sourcebot/pull/597)
1314

1415
### Fixed
1516
- [ask sb] Fixed issue where reasoning tokens would appear in `text` content for openai compatible models. [#582](https://github.com/sourcebot-dev/sourcebot/pull/582)

Dockerfile

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,10 @@ COPY package.json yarn.lock* .yarnrc.yml ./
4242
COPY .yarn ./.yarn
4343
COPY ./packages/db ./packages/db
4444
COPY ./packages/schemas ./packages/schemas
45-
COPY ./packages/crypto ./packages/crypto
46-
COPY ./packages/error ./packages/error
47-
COPY ./packages/logger ./packages/logger
4845
COPY ./packages/shared ./packages/shared
4946

5047
RUN yarn workspace @sourcebot/db install
5148
RUN yarn workspace @sourcebot/schemas install
52-
RUN yarn workspace @sourcebot/crypto install
53-
RUN yarn workspace @sourcebot/error install
54-
RUN yarn workspace @sourcebot/logger install
5549
RUN yarn workspace @sourcebot/shared install
5650
# ------------------------------------
5751

@@ -97,9 +91,6 @@ COPY ./packages/web ./packages/web
9791
COPY --from=shared-libs-builder /app/node_modules ./node_modules
9892
COPY --from=shared-libs-builder /app/packages/db ./packages/db
9993
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
100-
COPY --from=shared-libs-builder /app/packages/crypto ./packages/crypto
101-
COPY --from=shared-libs-builder /app/packages/error ./packages/error
102-
COPY --from=shared-libs-builder /app/packages/logger ./packages/logger
10394
COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
10495

10596
# Fixes arm64 timeouts
@@ -138,9 +129,6 @@ COPY ./packages/backend ./packages/backend
138129
COPY --from=shared-libs-builder /app/node_modules ./node_modules
139130
COPY --from=shared-libs-builder /app/packages/db ./packages/db
140131
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
141-
COPY --from=shared-libs-builder /app/packages/crypto ./packages/crypto
142-
COPY --from=shared-libs-builder /app/packages/error ./packages/error
143-
COPY --from=shared-libs-builder /app/packages/logger ./packages/logger
144132
COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
145133
RUN yarn workspace @sourcebot/backend install
146134
RUN yarn workspace @sourcebot/backend build
@@ -185,7 +173,6 @@ ENV DATA_DIR=/data
185173
ENV DATA_CACHE_DIR=$DATA_DIR/.sourcebot
186174
ENV DATABASE_DATA_DIR=$DATA_CACHE_DIR/db
187175
ENV REDIS_DATA_DIR=$DATA_CACHE_DIR/redis
188-
ENV REDIS_URL="redis://localhost:6379"
189176
ENV SRC_TENANT_ENFORCEMENT_MODE=strict
190177
ENV SOURCEBOT_PUBLIC_KEY_PATH=/app/public.pem
191178

@@ -225,9 +212,6 @@ COPY --from=backend-builder /app/packages/backend ./packages/backend
225212
COPY --from=shared-libs-builder /app/node_modules ./node_modules
226213
COPY --from=shared-libs-builder /app/packages/db ./packages/db
227214
COPY --from=shared-libs-builder /app/packages/schemas ./packages/schemas
228-
COPY --from=shared-libs-builder /app/packages/crypto ./packages/crypto
229-
COPY --from=shared-libs-builder /app/packages/error ./packages/error
230-
COPY --from=shared-libs-builder /app/packages/logger ./packages/logger
231215
COPY --from=shared-libs-builder /app/packages/shared ./packages/shared
232216

233217
# Configure dependencies

Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ clean:
2828
packages/db/dist \
2929
packages/schemas/node_modules \
3030
packages/schemas/dist \
31-
packages/crypto/node_modules \
32-
packages/crypto/dist \
33-
packages/error/node_modules \
34-
packages/error/dist \
3531
packages/mcp/node_modules \
3632
packages/mcp/dist \
3733
packages/shared/node_modules \

docs/docs/configuration/config-file.mdx

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ title: Config File
33
sidebarTitle: Config file
44
---
55

6+
import ConfigSchema from '/snippets/schemas/v3/index.schema.mdx'
7+
import EnvironmentOverridesSchema from '/snippets/schemas/v3/environmentOverrides.schema.mdx'
8+
69
When self-hosting Sourcebot, you **must** provide it a config file. This is done by defining a config file in a volume that's mounted to Sourcebot, and providing the path to this
710
file in the `CONFIG_PATH` environment variable. For example:
811

@@ -49,3 +52,103 @@ The following are settings that can be provided in your config file to modify So
4952
| `enablePublicAccess` **(deprecated)** | boolean | false || Use the `FORCE_ENABLE_ANONYMOUS_ACCESS` environment variable instead. |
5053
| `experiment_repoDrivenPermissionSyncIntervalMs` | number | 24 hours | 1 | Interval at which the repo permission syncer should run. |
5154
| `experiment_userDrivenPermissionSyncIntervalMs` | number | 24 hours | 1 | Interval at which the user permission syncer should run. |
55+
56+
# Tokens
57+
58+
Tokens are used to securely pass secrets to Sourcebot in a config file. They are used in various places, including connections, language model providers, auth providers, etc. Tokens can be passed as either environment variables or Google Cloud secrets:
59+
60+
<AccordionGroup>
61+
<Accordion title="Environment Variables">
62+
```json
63+
{
64+
"token": {
65+
"env": "TOKEN_NAME"
66+
}
67+
}
68+
```
69+
</Accordion>
70+
<Accordion title="Google Cloud Secrets">
71+
```json
72+
{
73+
"token": {
74+
"googleCloudSecret": "projects/<project-id>/secrets/<secret-name>/versions/<version-id>"
75+
}
76+
}
77+
```
78+
</Accordion>
79+
</AccordionGroup>
80+
81+
# Overriding environment variables from the config
82+
83+
You can override / set environment variables from the config file by using the `environmentOverrides` property. Overrides can be of type `string`, `number`, `boolean`, or a [token](/docs/configuration/config-file#tokens). Tokens are useful when you want to configure a environment variable using a Google Cloud Secret or other supported secret management service.
84+
85+
<AccordionGroup>
86+
<Accordion title="Token">
87+
```jsonc
88+
{
89+
"environmentOverrides": {
90+
"DATABASE_URL": {
91+
"type": "token",
92+
"value": {
93+
"googleCloudSecret": "projects/<id>/secrets/postgres-connection-string/versions/latest"
94+
}
95+
},
96+
"REDIS_URL": {
97+
"type": "token",
98+
"value": {
99+
"googleCloudSecret": "projects/<id>/secrets/redis-connection-string/versions/latest"
100+
}
101+
}
102+
},
103+
}
104+
```
105+
</Accordion>
106+
107+
<Accordion title="String">
108+
```jsonc
109+
{
110+
"environmentOverrides": {
111+
"EMAIL_FROM_ADDRESS": {
112+
"type": "string",
113+
"value": "hello@sourcebot.dev"
114+
}
115+
}
116+
}
117+
```
118+
</Accordion>
119+
120+
<Accordion title="Number">
121+
```jsonc
122+
{
123+
"environmentOverrides": {
124+
"SOURCEBOT_CHAT_MODEL_TEMPERATURE": {
125+
"type": "number",
126+
"value": 0.5
127+
}
128+
}
129+
}
130+
```
131+
</Accordion>
132+
133+
<Accordion title="Boolean">
134+
```jsonc
135+
{
136+
"environmentOverrides": {
137+
"SOURCEBOT_TELEMETRY_DISABLED": {
138+
"type": "boolean",
139+
"value": false
140+
}
141+
}
142+
}
143+
```
144+
</Accordion>
145+
</AccordionGroup>
146+
147+
148+
**Note:** Overrides are **not** set as system environment variables, and instead are resolved at runtime on startup and stored in memory.
149+
150+
<Accordion title="Schema reference">
151+
[schemas/v3/environmentOverrides.json](https://github.com/sourcebot-dev/sourcebot/blob/main/schemas/v3/environmentOverrides.json)
152+
153+
<EnvironmentOverridesSchema />
154+
</Accordion>

docs/docs/configuration/environment-variables.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
title: Environment variables
33
sidebarTitle: Environment variables
4-
mode: "wide"
54
---
65

76
<Note>This page provides a detailed reference of all environment variables supported by Sourcebot. If you're just looking to get up and running, we recommend starting with the [deployment guide](/docs/deployment-guide) instead.</Note>
@@ -71,3 +70,6 @@ The following environment variables allow you to configure your Sourcebot deploy
7170
| `REVIEW_AGENT_LOGGING_ENABLED` | `true` | <p>Enables/disables logging for the review agent. Logs are saved in `DATA_CACHE_DIR/review-agent`</p> |
7271
| `REVIEW_AGENT_REVIEW_COMMAND` | `review` | <p>The command used to trigger a code review by the review agent.</p> |
7372

73+
### Overriding environment variables from the config
74+
75+
You can override environment variables from the config file by using the `environmentOverrides` property. See [this doc](/docs/configuration/config-file#overriding-environment-variables-from-the-config) for more info.

docs/docs/configuration/idp.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ External identity providers can be used for [authentication](/docs/configuration
2020
"provider": "github",
2121
"purpose": "account_linking",
2222
"accountLinkingRequired": true,
23-
/*
24-
Secrets are provided through environment variables. Set the secret into
25-
an env var and provide the name here to tell Sourcebot where to get
26-
the value
27-
*/
2823
"clientId": {
2924
"env": "GITHUB_IDENTITY_PROVIDER_CLIENT_ID"
3025
},
@@ -45,6 +40,8 @@ the value
4540
}
4641
```
4742

43+
Secret values (such as `clientId` and `clientSecret`) can be provided as environment variables or Google Cloud secrets via [tokens](/docs/configuration/config-file#tokens).
44+
4845
# Supported External Identity Providers
4946

5047
Sourcebot uses [Auth.js](https://authjs.dev/) to connect to external identity providers. If there's a provider supported by Auth.js that you don't see below, please submit a

docs/docs/connections/ado-cloud.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
8686
Azure Devops Cloud requires you to provide a PAT in order to index your repositories. To learn how to create PAT, check out the [Azure Devops docs](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows).
8787
Sourcebot needs the `Read` access for the `Code` scope in order to find and clone your repos.
8888

89-
Next, provide the access token via an environment variable which is referenced in the `token` property:
89+
Next, provide the access [token](/docs/configuration/config-file#tokens) via an environment variable which is referenced in the `token` property:
9090

9191
<Tabs>
9292
<Tab title="Environment Variable">

docs/docs/connections/ado-server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
100100
Azure Devops Server requires you to provide a PAT in order to index your repositories. To learn how to create PAT, check out the [Azure Devops docs](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows).
101101
Sourcebot needs the `Read` access for the `Code` scope in order to find and clone your repos.
102102

103-
Next, provide the access token via an environment variable which is referenced in the `token` property:
103+
Next, provide the access [token](/docs/configuration/config-file#tokens) via an environment variable which is referenced in the `token` property:
104104

105105
<Tabs>
106106
<Tab title="Environment Variable">

docs/docs/connections/bitbucket-cloud.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ If you're not familiar with Sourcebot [connections](/docs/connections/overview),
7878

7979
## Authenticating with Bitbucket Cloud
8080

81-
In order to index private repositories, you'll need to provide authentication credentials. You can do this using an `App Password` or an `Access Token`
81+
In order to index private repositories, you'll need to provide authentication credentials via a [token](/docs/configuration/config-file#tokens). You can do this using an `App Password` or an `Access Token`
8282

8383
<Tabs>
8484
<Tab title="App Password">

0 commit comments

Comments
 (0)