diff --git a/docs/config/config-file.mdx b/docs/config/config-file.mdx index 93fe8359a6..dfc95fcb1c 100644 --- a/docs/config/config-file.mdx +++ b/docs/config/config-file.mdx @@ -13,8 +13,8 @@ The `trigger.config.ts` file is used to configure your Trigger.dev project. It i import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //Your project ref (you can see it on the Project settings page in the dashboard) - project: "proj_gtcwttqhhtlasxgfuhxs", + // Your project ref (you can see it on the Project settings page in the dashboard) + project: "", //The paths for your trigger folders dirs: ["./trigger"], retries: { @@ -55,7 +55,8 @@ You can add lifecycle functions to get notified when any task starts, succeeds, import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... onSuccess: async (payload, output, { ctx }) => { console.log("Task succeeded", ctx.task.id); }, @@ -87,7 +88,8 @@ import { PrismaInstrumentation } from "@prisma/instrumentation"; import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... instrumentations: [new PrismaInstrumentation(), new OpenAIInstrumentation()], }); ``` @@ -115,7 +117,8 @@ We currently only officially support the `node` runtime, but you can try our exp import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... runtime: "bun", }); ``` @@ -130,7 +133,8 @@ You can specify the default machine for all tasks in your project: import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... defaultMachine: "large-1x", }); ``` @@ -145,7 +149,8 @@ You can set the log level for your project: import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... logLevel: "debug", }); ``` @@ -160,7 +165,8 @@ You can set the default `maxDuration` for all tasks in your project: import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... maxDuration: 60, // 60 seconds }); ``` @@ -175,7 +181,8 @@ You can customize the build process using the `build` option: import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { // Don't bundle these packages external: ["header-generator"], @@ -197,7 +204,8 @@ All code is bundled by default, but you can exclude some packages from the bundl import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { external: ["header-generator"], }, @@ -212,7 +220,8 @@ Each entry in the external should be a package name, not necessarily the import import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { external: ["ai"], }, @@ -232,7 +241,8 @@ You can customize the `jsx` options that are passed to `esbuild` using the `jsx` import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { jsx: { // Use the Fragment component instead of React.Fragment @@ -258,7 +268,8 @@ You can add custom [import conditions](https://esbuild.github.io/api/#conditions import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { conditions: ["react-server"], }, @@ -282,7 +293,8 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { additionalFiles } from "@trigger.dev/build/extensions/core"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [ additionalFiles({ files: ["wrangler/wrangler.toml", "./assets/**", "./fonts/**"] }), @@ -304,7 +316,8 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { additionalPackages } from "@trigger.dev/build/extensions/core"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [additionalPackages({ packages: ["wrangler"] })], }, @@ -317,7 +330,8 @@ This allows you to include additional packages in the build that are not automat import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [additionalPackages({ packages: ["wrangler@1.19.0"] })], }, @@ -334,6 +348,7 @@ import { emitDecoratorMetadata } from "@trigger.dev/build/extensions/typescript" export default defineConfig({ project: "", + // Your other config settings... build: { extensions: [emitDecoratorMetadata()], }, @@ -365,6 +380,8 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { prismaExtension } from "@trigger.dev/build/extensions/prisma"; export default defineConfig({ + project: "", + // Your other config settings... build: { extensions: [ prismaExtension({ @@ -389,6 +406,7 @@ import { prismaExtension } from "@trigger.dev/build/extensions/prisma"; export default defineConfig({ project: "", + // Your other config settings... build: { extensions: [ prismaExtension({ @@ -431,6 +449,7 @@ import { prismaExtension } from "@trigger.dev/build/extensions/prisma"; export default defineConfig({ project: "", + // Your other config settings... build: { extensions: [ prismaExtension({ @@ -451,6 +470,7 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ project: "", + // Your other config settings... build: { extensions: [ prismaExtension({ @@ -473,6 +493,43 @@ These environment variables are only used during the build process and are not e 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. +```ts +import { syncEnvVars } from "@trigger.dev/build/extensions/core"; + +export default defineConfig({ + project: "", + // Your other config settings... + build: { + extensions: [syncEnvVars()], + }, +}); +``` + +#### vercelSyncEnvVars + +The `vercelSyncEnvVars` build extension syncs environment variables from your Vercel project to Trigger.dev. + + + You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables, or pass + in the token and project ID as arguments to the `vercelSyncEnvVars` build extension. You can find + / generate the `VERCEL_ACCESS_TOKEN` in your Vercel + [dashboard](https://vercel.com/account/settings/tokens). Make sure the scope of the token covers + the project you want to sync. + + +```ts +import { defineConfig } from "@trigger.dev/sdk/v3"; +import { vercelSyncEnvVars } from "@trigger.dev/build/extensions/core"; + +export default defineConfig({ + project: "", + // Your other config settings... + build: { + extensions: [vercelSyncEnvVars()], + }, +}); +``` + #### audioWaveform Previously, we installed [Audio Waveform](https://github.com/bbc/audiowaveform) in the build image. That's been moved to a build extension: @@ -482,7 +539,8 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { audioWaveform } from "@trigger.dev/build/extensions/audioWaveform"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [audioWaveform()], // uses verson 1.1.0 of audiowaveform by default }, @@ -525,6 +583,7 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { ffmpeg } from "@trigger.dev/build/extensions/core"; export default defineConfig({ + project: "", // Your other config settings... build: { extensions: [ffmpeg()], @@ -539,7 +598,8 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { ffmpeg } from "@trigger.dev/build/extensions/core"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [ffmpeg({ version: "6.0-4" })], }, @@ -561,6 +621,7 @@ import { sentryEsbuildPlugin } from "@sentry/esbuild-plugin"; export default defineConfig({ project: "", + // Your other config settings... build: { extensions: [ esbuildPlugin( @@ -586,7 +647,8 @@ import { defineConfig } from "@trigger.dev/sdk/v3"; import { aptGet } from "@trigger.dev/build/extensions/core"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [aptGet({ packages: ["ffmpeg"] })], }, @@ -599,7 +661,8 @@ If you want to install a specific version of a package, you can specify the vers import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [aptGet({ packages: ["ffmpeg=6.0-4"] })], }, @@ -646,7 +709,8 @@ Instead of creating this function and worrying about types, you can define an ex import { defineConfig } from "@trigger.dev/sdk/v3"; export default defineConfig({ - //..other stuff + project: "", + // Your other config settings... build: { extensions: [ { diff --git a/docs/deploy-environment-variables.mdx b/docs/deploy-environment-variables.mdx index d9d510bd8a..3f67a5bb6a 100644 --- a/docs/deploy-environment-variables.mdx +++ b/docs/deploy-environment-variables.mdx @@ -123,6 +123,10 @@ export default defineConfig({ }); ``` +#### Syncing environment variables from Vercel + +To sync environment variables from your Vercel projects to Trigger.dev, you can use our build extension. Check out our [syncing environment variables from Vercel guide](/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. diff --git a/docs/guides/examples/vercel-ai-sdk.mdx b/docs/guides/examples/vercel-ai-sdk.mdx index 755b87859a..db4f7306a5 100644 --- a/docs/guides/examples/vercel-ai-sdk.mdx +++ b/docs/guides/examples/vercel-ai-sdk.mdx @@ -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"; + ## 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). @@ -51,3 +53,5 @@ To test this task in the dashboard, you can use the following payload: "prompt": "What is the meaning of life?" } ``` + + diff --git a/docs/guides/examples/vercel-sync-env-vars.mdx b/docs/guides/examples/vercel-sync-env-vars.mdx new file mode 100644 index 0000000000..8908d7ee28 --- /dev/null +++ b/docs/guides/examples/vercel-sync-env-vars.mdx @@ -0,0 +1,53 @@ +--- +title: "Syncing environment variables from your Vercel projects" +sidebarTitle: "Vercel sync environment variables" +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, you just need to add our build extension to your `trigger.config.ts` file. This extension will then automatically run every time you deploy your Trigger.dev project. + + + You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables in the + Trigger.dev dashboard, or pass in the token and project ID as arguments to the `vercelSyncEnvVars` + build extension. You can find / generate the `VERCEL_ACCESS_TOKEN` in your Vercel + [dashboard](https://vercel.com/account/settings/tokens). Make sure the scope of the token covers + the project with the environment variables you want to sync. + + +```ts trigger.config.ts +import { defineConfig } from "@trigger.dev/sdk/v3"; +import { vercelSyncEnvVars } from "@trigger.dev/build/extensions/core"; + +export default defineConfig({ + project: "", + // Your other config settings... + build: { + // Add the vercelSyncEnvVars build extension + extensions: [vercelSyncEnvVars()], + }, +}); +``` + + + [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. + + +## Running the sync operation + +To sync the environment variables, all you need to do is run our `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 your Trigger.dev dashboard. + +```bash +npx trigger.dev@latest deploy +``` + + diff --git a/docs/guides/frameworks/nextjs-webhooks.mdx b/docs/guides/frameworks/nextjs-webhooks.mdx index 4581450f9b..fbbfbf30e5 100644 --- a/docs/guides/frameworks/nextjs-webhooks.mdx +++ b/docs/guides/frameworks/nextjs-webhooks.mdx @@ -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) @@ -135,3 +137,5 @@ If you now go to your [Trigger.dev dashboard](https://cloud.trigger.dev), you sh + + diff --git a/docs/guides/frameworks/nextjs.mdx b/docs/guides/frameworks/nextjs.mdx index c14801cfe9..8cd8ac1583 100644 --- a/docs/guides/frameworks/nextjs.mdx +++ b/docs/guides/frameworks/nextjs.mdx @@ -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"; This guide can be followed for both App and Pages router as well as Server Actions. @@ -244,16 +245,42 @@ Here are the steps to trigger your task in the Next.js App and Pages router and +## Automatically sync environment variables from your Vercel project (optional) + +If you want to automatically sync environment variables from your Vercel project to Trigger.dev, you can add our `vercelSyncEnvVars` build extension to your `trigger.config.ts` file. + + + You need to set the `VERCEL_ACCESS_TOKEN` and `VERCEL_PROJECT_ID` environment variables, or pass + in the token and project ID as arguments to the `vercelSyncEnvVars` build extension. You can find + / generate the `VERCEL_ACCESS_TOKEN` in your Vercel + [dashboard](https://vercel.com/account/settings/tokens). Make sure the scope of the token covers + the project you want to sync. + + +```ts trigger.config.ts +import { defineConfig } from "@trigger.dev/sdk/v3"; +import { vercelSyncEnvVars } from "@trigger.dev/build/extensions/core"; + +export default defineConfig({ + project: "", + // Your other config settings... + build: { + extensions: [vercelSyncEnvVars()], + }, +}); +``` + + + For more information, see our [Vercel sync environment + variables](/guides/examples/vercel-sync-env-vars) guide. + + ## Troubleshooting & extra resources - - - - ### Revalidation from your Trigger.dev tasks [Revalidation](https://vercel.com/docs/incremental-static-regeneration/quickstart#on-demand-revalidation) allows you to purge the cache for an ISR route. To revalidate an ISR route from a Trigger.dev task, you have to set up a handler for the `revalidate` event. This is an API route that you can add to your Next.js app. @@ -398,14 +425,9 @@ You can test your revalidation task in the Trigger.dev dashboard on the testing } ``` -## Additional resources for Next.js - - - How to create a webhook handler in a Next.js app, and trigger a task from it. - + + + + diff --git a/docs/guides/introduction.mdx b/docs/guides/introduction.mdx index 88dab5d3aa..df3f7239bd 100644 --- a/docs/guides/introduction.mdx +++ b/docs/guides/introduction.mdx @@ -55,6 +55,7 @@ Tasks you can copy and paste to get started with Trigger.dev. They can all be ex | [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. | If you would like to see a guide for your framework, or an example task for your use case, please diff --git a/docs/mint.json b/docs/mint.json index 6bc9a2a10d..3b34bfcc87 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -342,7 +342,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" ] }, { diff --git a/docs/snippets/add-environment-variables.mdx b/docs/snippets/add-environment-variables.mdx index b82a6c56fe..349cb5721e 100644 --- a/docs/snippets/add-environment-variables.mdx +++ b/docs/snippets/add-environment-variables.mdx @@ -1,4 +1,4 @@ -## Add your environment variables (optional) +## Manually add your environment variables (optional) If you have any environment variables in your tasks, be sure to add them in the dashboard so deployed code runs successfully. In Node.js, these environment variables are accessed in your code using `process.env.MY_ENV_VAR`. @@ -8,4 +8,4 @@ button. ![Environment variables page](/images/environment-variables-page.jpg) You can add values for your local dev environment, staging and prod. ![Environment variables page](/images/environment-variables-panel.jpg) -You can also add environment variables in code by following the steps on the [Environment Variables page](/deploy-environment-variables#in-your-code). \ No newline at end of file +You can also add environment variables in code by following the steps on the [Environment Variables page](/deploy-environment-variables#in-your-code). diff --git a/docs/snippets/vercel-docs-cards.mdx b/docs/snippets/vercel-docs-cards.mdx new file mode 100644 index 0000000000..afc45ded47 --- /dev/null +++ b/docs/snippets/vercel-docs-cards.mdx @@ -0,0 +1,33 @@ +## Learn more about Vercel and Trigger.dev + +### Walk-through guides from development to deployment + + + + Learn how to setup Trigger.dev with Next.js, using either the pages or app router. + + + + Learn how to create a webhook handler for incoming webhooks in a Next.js app, and trigger a task from it. + + + +### Task examples + + + + Learn how to automatically sync environment variables from your Vercel projects to Trigger.dev. + + + 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. + +