Skip to content

Commit 76fe7b7

Browse files
committed
feat(buildExtensions): syncSupabaseEnvVars build extension
1 parent dee6f1d commit 76fe7b7

File tree

6 files changed

+382
-2
lines changed

6 files changed

+382
-2
lines changed

apps/webapp/app/components/integrations/VercelOnboardingModal.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,31 @@ export function VercelOnboardingModal({
851851
Later on environment variables can be pulled before each build.
852852
</Paragraph>
853853

854+
<Callout variant="info">
855+
<p className="text-xs">
856+
Using Supabase Branching or Neon Database Branching? Pull env vars now, then
857+
disable syncing for database env vars on the Environment Variables page and use{" "}
858+
<a
859+
href="https://trigger.dev/docs/config/extensions/syncEnvVars#syncsupabaseenvvars"
860+
className="text-text-bright underline underline-offset-2 transition hover:text-text-link"
861+
target="_blank"
862+
rel="noopener noreferrer"
863+
>
864+
syncSupabaseEnvVars
865+
</a>{" "}
866+
or{" "}
867+
<a
868+
href="https://trigger.dev/docs/config/extensions/syncEnvVars#syncneonenvvars"
869+
className="text-text-bright underline underline-offset-2 transition hover:text-text-link"
870+
target="_blank"
871+
rel="noopener noreferrer"
872+
>
873+
syncNeonEnvVars
874+
</a>{" "}
875+
build extensions instead.
876+
</p>
877+
</Callout>
878+
854879
<div className="flex gap-4 text-sm">
855880
<div className="rounded border bg-charcoal-750 px-3 py-2">
856881
<span className="font-medium text-text-bright">{syncableEnvVars.length}</span>

docs/config/extensions/overview.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Trigger.dev provides a set of built-in extensions that you can use to customize
5757
| [additionalPackages](/config/extensions/additionalPackages) | Install additional npm packages in your build image |
5858
| [syncEnvVars](/config/extensions/syncEnvVars) | Automatically sync environment variables from external services to Trigger.dev |
5959
| [syncVercelEnvVars](/config/extensions/syncEnvVars#syncVercelEnvVars) | Automatically sync environment variables from Vercel to Trigger.dev |
60+
| [syncSupabaseEnvVars](/config/extensions/syncEnvVars#syncSupabaseEnvVars) | Automatically sync environment variables from Supabase to Trigger.dev |
6061
| [esbuildPlugin](/config/extensions/esbuildPlugin) | Add existing or custom esbuild extensions to customize your build process |
6162
| [emitDecoratorMetadata](/config/extensions/emitDecoratorMetadata) | Enable `emitDecoratorMetadata` in your TypeScript build |
6263
| [audioWaveform](/config/extensions/audioWaveform) | Add Audio Waveform to your build image |

docs/config/extensions/syncEnvVars.mdx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,72 @@ The extension syncs the following environment variables (with optional prefix):
220220
- `POSTGRES_PRISMA_URL` - Connection string optimized for Prisma
221221
- `POSTGRES_HOST`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_DATABASE`
222222
- `PGHOST`, `PGHOST_UNPOOLED`, `PGUSER`, `PGPASSWORD`, `PGDATABASE`
223+
224+
### syncSupabaseEnvVars
225+
226+
The `syncSupabaseEnvVars` build extension syncs environment variables from your Supabase project to Trigger.dev. It uses [Supabase Branching](https://supabase.com/docs/guides/deployment/branching) to automatically detect branches and build the appropriate database connection strings and API keys for your environment.
227+
228+
<AccordionGroup>
229+
<Accordion title="Setting up authentication">
230+
You need to set the `SUPABASE_ACCESS_TOKEN` and `SUPABASE_PROJECT_ID` environment variables, or pass them
231+
as arguments to the `syncSupabaseEnvVars` build extension.
232+
233+
You can generate a `SUPABASE_ACCESS_TOKEN` in your Supabase [dashboard](https://supabase.com/dashboard/account/tokens).
234+
</Accordion>
235+
236+
<Accordion title="Running in Vercel environment">
237+
When running the build from a Vercel environment (determined by checking if the `VERCEL`
238+
environment variable is present), this extension is skipped entirely.
239+
</Accordion>
240+
</AccordionGroup>
241+
242+
<Note>
243+
For `prod` and `dev` environments, this extension uses credentials from your default Supabase
244+
branch. For `preview` and `staging` environments, it matches the git branch name to a Supabase
245+
branch and syncs the corresponding database connection strings and API keys.
246+
</Note>
247+
248+
```ts
249+
import { defineConfig } from "@trigger.dev/sdk";
250+
import { syncSupabaseEnvVars } from "@trigger.dev/build/extensions/core";
251+
252+
export default defineConfig({
253+
project: "<project ref>",
254+
// Your other config settings...
255+
build: {
256+
// This will automatically use the SUPABASE_ACCESS_TOKEN and SUPABASE_PROJECT_ID environment variables
257+
extensions: [syncSupabaseEnvVars()],
258+
},
259+
});
260+
```
261+
262+
Or you can pass in the token, project ID, and other options as arguments:
263+
264+
```ts
265+
import { defineConfig } from "@trigger.dev/sdk";
266+
import { syncSupabaseEnvVars } from "@trigger.dev/build/extensions/core";
267+
268+
export default defineConfig({
269+
project: "<project ref>",
270+
// Your other config settings...
271+
build: {
272+
extensions: [
273+
syncSupabaseEnvVars({
274+
projectId: "your-supabase-project-id",
275+
supabaseAccessToken: "your-supabase-access-token", // optional, we recommend to keep it as env variable
276+
branch: "your-branch-name", // optional, defaults to ctx.branch
277+
envVarPrefix: "MY_PREFIX_", // optional, prefix for all synced env vars
278+
}),
279+
],
280+
},
281+
});
282+
```
283+
284+
The extension syncs the following environment variables (with optional prefix):
285+
286+
- `DATABASE_URL`, `POSTGRES_URL`, `SUPABASE_DB_URL` — PostgreSQL connection strings
287+
- `PGHOST`, `PGPORT`, `PGUSER`, `PGPASSWORD`, `PGDATABASE` — Individual connection parameters
288+
- `SUPABASE_URL` — Supabase API URL
289+
- `SUPABASE_ANON_KEY` — Anonymous API key
290+
- `SUPABASE_SERVICE_ROLE_KEY` — Service role API key
291+
- `SUPABASE_JWT_SECRET` — JWT secret

docs/vercel-integration.mdx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ The following variables are excluded from the Vercel → Trigger.dev sync:
105105
You can control sync behavior per-variable from your project's Vercel settings. Deselecting a variable prevents its value from being updated during future syncs.
106106

107107
<Tip>
108-
For dynamic environment variables (e.g., from NeonDB branching), use the `syncEnvVars` build
109-
extension instead. Learn more about [environment variables](/deploy-environment-variables).
108+
If you use [Supabase Branching](https://supabase.com/docs/guides/deployment/branching) or [Neon
109+
Database Branching](https://neon.tech/docs/guides/branching-intro) for preview environments,
110+
disable syncing for database env vars on the Environment Variables page and use the
111+
[syncSupabaseEnvVars](/config/extensions/syncEnvVars#syncsupabaseenvvars) or
112+
[syncNeonEnvVars](/config/extensions/syncEnvVars#syncneonenvvars) build extensions instead. These
113+
extensions automatically resolve the correct branch-specific credentials at build time.
110114
</Tip>
111115

112116
## Atomic deployments

packages/build/src/extensions/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from "./core/aptGet.js";
55
export * from "./core/ffmpeg.js";
66
export * from "./core/neonSyncEnvVars.js";
77
export * from "./core/vercelSyncEnvVars.js";
8+
export * from "./core/syncSupabaseEnvVars.js";

0 commit comments

Comments
 (0)