Skip to content
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

Docs - sync vercel env vars #1426

Merged
merged 22 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/config/config-file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ These environment variables are only used during the build process and are not e

#### syncEnvVars

The `syncEnvVars` build extension replaces the deprecated `resolveEnvVars` export. Check out our [syncEnvVars documentation](/deploy-environment-variables#sync-env-vars-from-another-service) for more information.
D-K-P marked this conversation as resolved.
Show resolved Hide resolved
The `syncEnvVars` build extension replaces the deprecated `resolveEnvVars` export. Check out our [syncEnvVars documentation](/deploy-environment-variables#sync-env-vars-from-another-service) for more information and example usage (including syncing environment variables from Infisical and Vercel).

matt-aitken marked this conversation as resolved.
Show resolved Hide resolved
#### audioWaveform

Expand Down
4 changes: 4 additions & 0 deletions docs/deploy-environment-variables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export default defineConfig({
});
```

#### Syncing environment variables from Vercel

To sync environment variables from your Vercel projects to Trigger.dev, check out our [syncing environment variables from Vercel example](/guides/examples/vercel-sync-env-vars).

#### Deploy

When you run the [CLI deploy command](/cli-deploy) directly or using [GitHub Actions](/github-actions) it will sync the environment variables from [Infisical](https://infisical.com) to Trigger.dev. This means they'll appear on the Environment Variables page so you can confirm that it's worked.
Expand Down
4 changes: 4 additions & 0 deletions docs/guides/examples/vercel-ai-sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebarTitle: "Vercel AI SDK"
description: "This example demonstrates how to use the Vercel AI SDK with Trigger.dev."
---

import VercelDocsCards from "/snippets/vercel-docs-cards.mdx";

matt-aitken marked this conversation as resolved.
Show resolved Hide resolved
## Overview

The [Vercel AI SDK](https://www.npmjs.com/package/ai) is a simple way to use AI models from many different providers, including OpenAI, Microsoft Azure, Google Generative AI, Anthropic, Amazon Bedrock, Groq, Perplexity and [more](https://sdk.vercel.ai/providers/ai-sdk-providers).
Expand Down Expand Up @@ -51,3 +53,5 @@ To test this task in the dashboard, you can use the following payload:
"prompt": "What is the meaning of life?"
}
```

<VercelDocsCards />
87 changes: 87 additions & 0 deletions docs/guides/examples/vercel-sync-env-vars.mdx
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;
}),
Copy link
Member

Choose a reason for hiding this comment

The 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 />
4 changes: 4 additions & 0 deletions docs/guides/frameworks/nextjs-webhooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ sidebarTitle: "Next.js webhooks"
description: "Learn how to trigger a task from a webhook in a Next.js app."
---

import VercelDocsCards from "/snippets/vercel-docs-cards.mdx";

## Prerequisites

- [A Next.js project, set up with Trigger.dev](/guides/frameworks/nextjs)
Expand Down Expand Up @@ -135,3 +137,5 @@ If you now go to your [Trigger.dev dashboard](https://cloud.trigger.dev), you sh
</Step>

</Steps>

<VercelDocsCards />
12 changes: 2 additions & 10 deletions docs/guides/frameworks/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import NextjsTroubleshootingButtonSyntax from "/snippets/nextjs-button-syntax.md
import WorkerFailedToStartWhenRunningDevCommand from "/snippets/worker-failed-to-start.mdx";
import AddEnvironmentVariables from "/snippets/add-environment-variables.mdx";
import DeployingYourTask from "/snippets/deplopying-your-task.mdx";
import VercelDocsCards from "/snippets/vercel-docs-cards.mdx";

<Note>This guide can be followed for both App and Pages router as well as Server Actions.</Note>

Expand Down Expand Up @@ -254,14 +255,5 @@ Here are the steps to trigger your task in the Next.js App and Pages router and
<NextjsTroubleshootingButtonSyntax/>
<WorkerFailedToStartWhenRunningDevCommand/>
matt-aitken marked this conversation as resolved.
Show resolved Hide resolved

## Additional resources for Next.js

<Card
title="Next.js - triggering tasks using webhooks"
icon="N"
href="/guides/frameworks/nextjs-webhooks"
>
How to create a webhook handler in a Next.js app, and trigger a task from it.
</Card>

<VercelDocsCards />
<UsefulNextSteps />
29 changes: 15 additions & 14 deletions docs/guides/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ Get set up fast using our detailed walk-through guides.

Tasks you can copy and paste to get started with Trigger.dev. They can all be extended and customized to fit your needs.

| Example task | Description |
| :---------------------------------------------------------------------------- | :----------------------------------------------------------------------------- |
| [DALL·E 3 image generation](/guides/examples/dall-e3-generate-image) | Use OpenAI's GPT-4o and DALL·E 3 to generate an image and text. |
| [Deepgram audio transcription](/guides/examples/deepgram-transcribe-audio) | Transcribe audio using Deepgram's speech recognition API. |
| [FFmpeg video processing](/guides/examples/ffmpeg-video-processing) | Use FFmpeg to process a video in various ways and save it to Cloudflare R2. |
| [OpenAI with retrying](/guides/examples/open-ai-with-retrying) | Create a reusable OpenAI task with custom retry options. |
| [PDF to image](/guides/examples/pdf-to-image) | Use `MuPDF` to turn a PDF into images and save them to Cloudflare R2. |
| [React to PDF](/guides/examples/react-pdf) | Use `react-pdf` to generate a PDF and save it to Cloudflare R2. |
| [Puppeteer](/guides/examples/puppeteer) | Use Puppeteer to generate a PDF or scrape a webpage. |
| [Resend email sequence](/guides/examples/resend-email-sequence) | Send a sequence of emails over several days using Resend with Trigger.dev. |
| [Sharp image processing](/guides/examples/sharp-image-processing) | Use Sharp to process an image and save it to Cloudflare R2. |
| [Supabase database operations](/guides/examples/supabase-database-operations) | Run basic CRUD operations on a table in a Supabase database using Trigger.dev. |
| [Supabase Storage upload](/guides/examples/supabase-storage-upload) | Download a video from a URL and upload it to Supabase Storage using S3. |
| [Vercel AI SDK](/guides/examples/vercel-ai-sdk) | Use Vercel AI SDK to generate text using OpenAI. |
| Example task | Description |
| :---------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- |
| [DALL·E 3 image generation](/guides/examples/dall-e3-generate-image) | Use OpenAI's GPT-4o and DALL·E 3 to generate an image and text. |
| [Deepgram audio transcription](/guides/examples/deepgram-transcribe-audio) | Transcribe audio using Deepgram's speech recognition API. |
| [FFmpeg video processing](/guides/examples/ffmpeg-video-processing) | Use FFmpeg to process a video in various ways and save it to Cloudflare R2. |
| [OpenAI with retrying](/guides/examples/open-ai-with-retrying) | Create a reusable OpenAI task with custom retry options. |
| [PDF to image](/guides/examples/pdf-to-image) | Use `MuPDF` to turn a PDF into images and save them to Cloudflare R2. |
| [React to PDF](/guides/examples/react-pdf) | Use `react-pdf` to generate a PDF and save it to Cloudflare R2. |
| [Puppeteer](/guides/examples/puppeteer) | Use Puppeteer to generate a PDF or scrape a webpage. |
| [Resend email sequence](/guides/examples/resend-email-sequence) | Send a sequence of emails over several days using Resend with Trigger.dev. |
| [Sharp image processing](/guides/examples/sharp-image-processing) | Use Sharp to process an image and save it to Cloudflare R2. |
| [Supabase database operations](/guides/examples/supabase-database-operations) | Run basic CRUD operations on a table in a Supabase database using Trigger.dev. |
| [Supabase Storage upload](/guides/examples/supabase-storage-upload) | Download a video from a URL and upload it to Supabase Storage using S3. |
| [Vercel AI SDK](/guides/examples/vercel-ai-sdk) | Use Vercel AI SDK to generate text using OpenAI. |
| [Vercel sync environment variables](/guides/examples/vercel-sync-env-vars) | Automatically sync environment variables from your Vercel projects to Trigger.dev. |

<Note>
If you would like to see a guide for your framework, or an example task for your use case, please
Expand Down
3 changes: 2 additions & 1 deletion docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@
"guides/examples/supabase-storage-upload",
"guides/examples/react-pdf",
"guides/examples/resend-email-sequence",
"guides/examples/vercel-ai-sdk"
"guides/examples/vercel-ai-sdk",
"guides/examples/vercel-sync-env-vars"
]
},
{
Expand Down
33 changes: 33 additions & 0 deletions docs/snippets/vercel-docs-cards.mdx
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>