-
-
Notifications
You must be signed in to change notification settings - Fork 808
Docs - sync vercel env vars #1426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e74e16a
Added sync env vars docs example
D-K-P 7e7c02b
Added links in the config + deploy files
D-K-P ddc6b0f
Updated copy
D-K-P 9341e95
Merge branch 'main' into docs/vercel-sync-env-vars
D-K-P e98e701
Added vercel docs cards and added them to all of the relevant docs pages
D-K-P f701ea1
Added sync env vars to the intro page
D-K-P f075499
Added automatically sync env vars section to nextjs guide
D-K-P 21d41f2
Added ‘Manually’
D-K-P d0fa045
Removed code block and updated title
D-K-P 08f1ddb
updated formatting and added vercelsyncenvvars to the config file
D-K-P 45f3230
Added missing comment
D-K-P 251a1ee
Merge branch 'main' into docs/vercel-sync-env-vars
D-K-P 8fbbfd1
Updated imports to /core
D-K-P 04a3c44
Merge branch 'main' into docs/vercel-sync-env-vars
D-K-P 99507ba
Added sync env var docs link and note
D-K-P 478bdc6
Improved the VERCEL_ACCESS_TOKEN note
D-K-P 4224813
Added link to vercel
D-K-P bcc330d
Merge remote-tracking branch 'origin/main' into docs/vercel-sync-env-…
D-K-P 2335d26
Updated docs and improved formatting
D-K-P b71892c
Copy tweaks
D-K-P 9c402e0
Added space
D-K-P d3f6993
Updated deploy docs
D-K-P File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
title: "Syncing environment variables from your Vercel projects" | ||
sidebarTitle: "Syncing Vercel env vars" | ||
description: "This example demonstrates how to sync environment variables from your Vercel project to Trigger.dev." | ||
--- | ||
|
||
import VercelDocsCards from "/snippets/vercel-docs-cards.mdx"; | ||
|
||
## Overview | ||
|
||
This example shows how to automatically sync environment variables from your Vercel project to Trigger.dev. | ||
|
||
## Build configuration | ||
|
||
To sync environment variables from your Vercel project to Trigger.dev, you'll first need to add this build configuration to your `trigger.config.ts` file. This extension will then automatically run every time you deploy your project. | ||
|
||
This code syncs encrypted environment variables, filtering them based on the current environment (production, preview, or development). | ||
|
||
matt-aitken marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```ts trigger.config.ts | ||
import { defineConfig } from "@trigger.dev/sdk/v3"; | ||
import { vercelSyncEnvVars } from "@trigger.dev/build/extensions/vercelSyncEnvVars"; | ||
|
||
export default defineConfig({ | ||
build: { | ||
extensions: | ||
extensions: [ | ||
syncVercelEnvVars(), | ||
syncEnvVars(async (ctx) => { | ||
const environmentMap = { | ||
// Account for the different environment names used by Vercel | ||
prod: "production", | ||
staging: "preview", | ||
dev: "development", | ||
} as const; | ||
|
||
const vercelEnvironment = | ||
environmentMap[ctx.environment as keyof typeof environmentMap]; | ||
|
||
const vercelApiUrl = | ||
`https://api.vercel.com/v8/projects/${process.env.VERCEL_PROJECT_ID}/env?decrypt=true`; | ||
|
||
const response = await fetch(vercelApiUrl, { | ||
headers: { | ||
Authorization: `Bearer ${process.env.VERCEL_ACCESS_TOKEN}`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
const filteredEnvs = data.envs | ||
.filter( | ||
(env: { type: string; value: string; target: string[] }) => | ||
env.type === "encrypted" && | ||
env.value && | ||
env.target.includes(vercelEnvironment), | ||
) | ||
.map((env: { key: string; value: string }) => ({ | ||
name: env.key, | ||
value: env.value, | ||
})); | ||
|
||
return filteredEnvs; | ||
}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this because the the syncVercelEnvVars extension does all of this |
||
],, | ||
}, | ||
}); | ||
``` | ||
|
||
<Note> | ||
[Build extensions](/config/config-file#extensions) allow you to hook into the build system and | ||
customize the build process or the resulting bundle and container image (in the case of | ||
deploying). You can use pre-built extensions or create your own. | ||
</Note> | ||
|
||
## Running the sync operation | ||
|
||
To run the sync operation, simply run the `deploy` command. You should see some output in the console indicating that the environment variables have been synced, and they should now be available in the Trigger.dev dashboard. | ||
|
||
```bash | ||
npx trigger.dev@latest deploy | ||
``` | ||
|
||
<VercelDocsCards /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
## Learn more about Vercel and Trigger.dev | ||
|
||
### Walk-through guides from development to deployment | ||
|
||
<CardGroup cols={2}> | ||
<Card title="Next.js - setup guide" icon="N" href="/guides/frameworks/nextjs"> | ||
Learn how to setup Trigger.dev with Next.js, using either the pages or app router. | ||
</Card> | ||
|
||
<Card | ||
title="Next.js - triggering tasks using webhooks" | ||
icon="N" | ||
href="/guides/frameworks/nextjs-webhooks" | ||
> | ||
Learn how to create a webhook handler for incoming webhooks in a Next.js app, and trigger a task from it. | ||
</Card> | ||
</CardGroup> | ||
|
||
### Task examples with code you can copy and paste | ||
|
||
<CardGroup cols={2}> | ||
<Card | ||
title="Vercel sync environment variables" | ||
icon="code" | ||
href="/guides/examples/vercel-sync-env-vars" | ||
> | ||
Learn how to automatically sync environment variables from your Vercel projects to Trigger.dev. | ||
</Card> | ||
<Card title="Vercel AI SDK" icon="code" href="/guides/examples/vercel-ai-sdk"> | ||
Learn how to use the Vercel AI SDK, which is a simple way to use AI models from different | ||
providers, including OpenAI, Anthropic, Amazon Bedrock, Groq, Perplexity etc. | ||
</Card> | ||
</CardGroup> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.