@trigger.dev/sdk 4.5.0-rc.5 → 4.5.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/v3/ai.d.ts +178 -5
- package/dist/commonjs/v3/ai.js +603 -119
- package/dist/commonjs/v3/ai.js.map +1 -1
- package/dist/commonjs/v3/chat-client.js +3 -0
- package/dist/commonjs/v3/chat-client.js.map +1 -1
- package/dist/commonjs/v3/chat-react.js +10 -7
- package/dist/commonjs/v3/chat-react.js.map +1 -1
- package/dist/commonjs/v3/chat-server.d.ts +8 -0
- package/dist/commonjs/v3/chat-server.js +32 -10
- package/dist/commonjs/v3/chat-server.js.map +1 -1
- package/dist/commonjs/v3/chat-server.test.js +51 -0
- package/dist/commonjs/v3/chat-server.test.js.map +1 -1
- package/dist/commonjs/v3/chat.js +34 -6
- package/dist/commonjs/v3/chat.js.map +1 -1
- package/dist/commonjs/v3/chat.test.js +53 -0
- package/dist/commonjs/v3/chat.test.js.map +1 -1
- package/dist/commonjs/v3/createStartSessionAction.test.js +30 -0
- package/dist/commonjs/v3/createStartSessionAction.test.js.map +1 -1
- package/dist/commonjs/v3/sessions.d.ts +11 -6
- package/dist/commonjs/v3/sessions.js +10 -5
- package/dist/commonjs/v3/sessions.js.map +1 -1
- package/dist/commonjs/v3/test/mock-chat-agent.d.ts +6 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js +1 -0
- package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/ai.d.ts +178 -5
- package/dist/esm/v3/ai.js +603 -120
- package/dist/esm/v3/ai.js.map +1 -1
- package/dist/esm/v3/chat-client.js +3 -0
- package/dist/esm/v3/chat-client.js.map +1 -1
- package/dist/esm/v3/chat-react.js +10 -7
- package/dist/esm/v3/chat-react.js.map +1 -1
- package/dist/esm/v3/chat-server.d.ts +8 -0
- package/dist/esm/v3/chat-server.js +32 -10
- package/dist/esm/v3/chat-server.js.map +1 -1
- package/dist/esm/v3/chat-server.test.js +51 -0
- package/dist/esm/v3/chat-server.test.js.map +1 -1
- package/dist/esm/v3/chat.js +34 -6
- package/dist/esm/v3/chat.js.map +1 -1
- package/dist/esm/v3/chat.test.js +53 -0
- package/dist/esm/v3/chat.test.js.map +1 -1
- package/dist/esm/v3/createStartSessionAction.test.js +30 -0
- package/dist/esm/v3/createStartSessionAction.test.js.map +1 -1
- package/dist/esm/v3/sessions.d.ts +11 -6
- package/dist/esm/v3/sessions.js +10 -5
- package/dist/esm/v3/sessions.js.map +1 -1
- package/dist/esm/v3/test/mock-chat-agent.d.ts +6 -0
- package/dist/esm/v3/test/mock-chat-agent.js +1 -0
- package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/docs/ai/prompts.mdx +430 -0
- package/docs/ai-chat/actions.mdx +115 -0
- package/docs/ai-chat/anatomy.mdx +71 -0
- package/docs/ai-chat/backend.mdx +817 -0
- package/docs/ai-chat/background-injection.mdx +221 -0
- package/docs/ai-chat/changelog.mdx +850 -0
- package/docs/ai-chat/chat-local.mdx +174 -0
- package/docs/ai-chat/client-protocol.mdx +1081 -0
- package/docs/ai-chat/compaction.mdx +411 -0
- package/docs/ai-chat/custom-agents.mdx +364 -0
- package/docs/ai-chat/error-handling.mdx +415 -0
- package/docs/ai-chat/fast-starts.mdx +672 -0
- package/docs/ai-chat/frontend.mdx +580 -0
- package/docs/ai-chat/how-it-works.mdx +230 -0
- package/docs/ai-chat/lifecycle-hooks.mdx +530 -0
- package/docs/ai-chat/mcp.mdx +101 -0
- package/docs/ai-chat/overview.mdx +90 -0
- package/docs/ai-chat/patterns/branching-conversations.mdx +284 -0
- package/docs/ai-chat/patterns/code-sandbox.mdx +126 -0
- package/docs/ai-chat/patterns/database-persistence.mdx +414 -0
- package/docs/ai-chat/patterns/human-in-the-loop.mdx +275 -0
- package/docs/ai-chat/patterns/large-payloads.mdx +169 -0
- package/docs/ai-chat/patterns/oom-resilience.mdx +120 -0
- package/docs/ai-chat/patterns/persistence-and-replay.mdx +211 -0
- package/docs/ai-chat/patterns/recovery-boot.mdx +230 -0
- package/docs/ai-chat/patterns/skills.mdx +221 -0
- package/docs/ai-chat/patterns/sub-agents.mdx +383 -0
- package/docs/ai-chat/patterns/tool-result-auditing.mdx +148 -0
- package/docs/ai-chat/patterns/trusted-edge-signals.mdx +337 -0
- package/docs/ai-chat/patterns/version-upgrades.mdx +172 -0
- package/docs/ai-chat/pending-messages.mdx +343 -0
- package/docs/ai-chat/prompt-caching.mdx +206 -0
- package/docs/ai-chat/quick-start.mdx +161 -0
- package/docs/ai-chat/reference.mdx +909 -0
- package/docs/ai-chat/server-chat.mdx +263 -0
- package/docs/ai-chat/sessions.mdx +333 -0
- package/docs/ai-chat/testing.mdx +682 -0
- package/docs/ai-chat/tools.mdx +191 -0
- package/docs/ai-chat/types.mdx +242 -0
- package/docs/ai-chat/upgrade-guide.mdx +515 -0
- package/docs/apikeys.mdx +54 -0
- package/docs/building-with-ai.mdx +261 -0
- package/docs/bulk-actions.mdx +49 -0
- package/docs/changelog.mdx +6 -0
- package/docs/cli-deploy-commands.mdx +9 -0
- package/docs/cli-dev-commands.mdx +9 -0
- package/docs/cli-dev.mdx +8 -0
- package/docs/cli-init-commands.mdx +58 -0
- package/docs/cli-introduction.mdx +25 -0
- package/docs/cli-list-profiles-commands.mdx +42 -0
- package/docs/cli-login-commands.mdx +33 -0
- package/docs/cli-logout-commands.mdx +33 -0
- package/docs/cli-preview-archive.mdx +59 -0
- package/docs/cli-promote-commands.mdx +9 -0
- package/docs/cli-switch.mdx +43 -0
- package/docs/cli-update-commands.mdx +42 -0
- package/docs/cli-whoami-commands.mdx +33 -0
- package/docs/community.mdx +6 -0
- package/docs/config/config-file.mdx +602 -0
- package/docs/config/extensions/additionalFiles.mdx +38 -0
- package/docs/config/extensions/additionalPackages.mdx +40 -0
- package/docs/config/extensions/aptGet.mdx +34 -0
- package/docs/config/extensions/audioWaveform.mdx +20 -0
- package/docs/config/extensions/custom.mdx +380 -0
- package/docs/config/extensions/emitDecoratorMetadata.mdx +29 -0
- package/docs/config/extensions/esbuildPlugin.mdx +31 -0
- package/docs/config/extensions/ffmpeg.mdx +45 -0
- package/docs/config/extensions/lightpanda.mdx +56 -0
- package/docs/config/extensions/overview.mdx +67 -0
- package/docs/config/extensions/playwright.mdx +195 -0
- package/docs/config/extensions/prismaExtension.mdx +1014 -0
- package/docs/config/extensions/puppeteer.mdx +30 -0
- package/docs/config/extensions/pythonExtension.mdx +182 -0
- package/docs/config/extensions/syncEnvVars.mdx +291 -0
- package/docs/context.mdx +235 -0
- package/docs/database-connections.mdx +213 -0
- package/docs/deploy-environment-variables.mdx +435 -0
- package/docs/deployment/atomic-deployment.mdx +172 -0
- package/docs/deployment/overview.mdx +257 -0
- package/docs/deployment/preview-branches.mdx +224 -0
- package/docs/errors-retrying.mdx +379 -0
- package/docs/github-actions.mdx +222 -0
- package/docs/github-integration.mdx +136 -0
- package/docs/github-repo.mdx +8 -0
- package/docs/help-email.mdx +6 -0
- package/docs/help-slack.mdx +11 -0
- package/docs/hidden-tasks.mdx +56 -0
- package/docs/how-it-works.mdx +454 -0
- package/docs/how-to-reduce-your-spend.mdx +217 -0
- package/docs/idempotency.mdx +504 -0
- package/docs/introduction.mdx +223 -0
- package/docs/limits.mdx +241 -0
- package/docs/logging.mdx +195 -0
- package/docs/machines.mdx +952 -0
- package/docs/manual-setup.mdx +632 -0
- package/docs/mcp-agent-rules.mdx +41 -0
- package/docs/mcp-introduction.mdx +385 -0
- package/docs/mcp-tools.mdx +273 -0
- package/docs/migrating-from-v3.mdx +334 -0
- package/docs/observability/dashboards.mdx +102 -0
- package/docs/observability/query.mdx +585 -0
- package/docs/open-source-contributing.mdx +16 -0
- package/docs/open-source-self-hosting.mdx +541 -0
- package/docs/private-networking/aws-console-setup.mdx +304 -0
- package/docs/private-networking/overview.mdx +144 -0
- package/docs/private-networking/troubleshooting.mdx +78 -0
- package/docs/queue-concurrency.mdx +354 -0
- package/docs/quick-start.mdx +97 -0
- package/docs/realtime/auth.mdx +208 -0
- package/docs/realtime/backend/overview.mdx +45 -0
- package/docs/realtime/backend/streams.mdx +418 -0
- package/docs/realtime/backend/subscribe.mdx +225 -0
- package/docs/realtime/how-it-works.mdx +94 -0
- package/docs/realtime/overview.mdx +63 -0
- package/docs/realtime/react-hooks/overview.mdx +73 -0
- package/docs/realtime/react-hooks/streams.mdx +449 -0
- package/docs/realtime/react-hooks/subscribe.mdx +674 -0
- package/docs/realtime/react-hooks/swr.mdx +87 -0
- package/docs/realtime/react-hooks/triggering.mdx +194 -0
- package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
- package/docs/realtime/run-object.mdx +174 -0
- package/docs/replaying.mdx +72 -0
- package/docs/request-feature.mdx +6 -0
- package/docs/roadmap.mdx +6 -0
- package/docs/run-tests.mdx +20 -0
- package/docs/run-usage.mdx +113 -0
- package/docs/runs/heartbeats.mdx +38 -0
- package/docs/runs/max-duration.mdx +139 -0
- package/docs/runs/metadata.mdx +734 -0
- package/docs/runs/priority.mdx +31 -0
- package/docs/runs.mdx +396 -0
- package/docs/self-hosting/docker.mdx +458 -0
- package/docs/self-hosting/env/supervisor.mdx +74 -0
- package/docs/self-hosting/env/webapp.mdx +276 -0
- package/docs/self-hosting/kubernetes.mdx +601 -0
- package/docs/self-hosting/overview.mdx +108 -0
- package/docs/skills.mdx +85 -0
- package/docs/tags.mdx +120 -0
- package/docs/tasks/overview.mdx +697 -0
- package/docs/tasks/scheduled.mdx +382 -0
- package/docs/tasks/schemaTask.mdx +413 -0
- package/docs/tasks/streams.mdx +884 -0
- package/docs/triggering.mdx +1320 -0
- package/docs/troubleshooting-alerts.mdx +385 -0
- package/docs/troubleshooting-debugging-in-vscode.mdx +8 -0
- package/docs/troubleshooting-github-issues.mdx +6 -0
- package/docs/troubleshooting-uptime-status.mdx +6 -0
- package/docs/troubleshooting.mdx +398 -0
- package/docs/upgrading-packages.mdx +80 -0
- package/docs/vercel-integration.mdx +207 -0
- package/docs/versioning.mdx +56 -0
- package/docs/video-walkthrough.mdx +23 -0
- package/docs/wait-for-token.mdx +540 -0
- package/docs/wait-for.mdx +42 -0
- package/docs/wait-until.mdx +53 -0
- package/docs/wait.mdx +18 -0
- package/docs/writing-tasks-introduction.mdx +33 -0
- package/package.json +10 -6
- package/skills/trigger-authoring-chat-agent/SKILL.md +296 -0
- package/skills/trigger-authoring-tasks/SKILL.md +254 -0
- package/skills/trigger-chat-agent-advanced/SKILL.md +368 -0
- package/skills/trigger-cost-savings/SKILL.md +116 -0
- package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Deployment"
|
|
3
|
+
sidebarTitle: "Overview"
|
|
4
|
+
description: "Learn how to deploy your tasks to Trigger.dev."
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
import CorepackError from "/snippets/corepack-error.mdx";
|
|
8
|
+
|
|
9
|
+
Before you can run production workloads on Trigger.dev, you need to deploy your tasks. The only way to do this at the moment is through the [deploy CLI command](/cli-deploy):
|
|
10
|
+
|
|
11
|
+
<CodeGroup>
|
|
12
|
+
|
|
13
|
+
```bash npm
|
|
14
|
+
npx trigger.dev@latest deploy
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash pnpm
|
|
18
|
+
pnpm dlx trigger.dev@latest deploy
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash yarn
|
|
22
|
+
yarn dlx trigger.dev@latest deploy
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
</CodeGroup>
|
|
26
|
+
|
|
27
|
+
## Deploying 101
|
|
28
|
+
|
|
29
|
+
Let's assume you have an existing trigger.dev project with a few tasks that you have been running locally but now want to deploy to the Trigger.dev cloud (or your self-hosted instance).
|
|
30
|
+
|
|
31
|
+
First, let's make sure you are logged in to the CLI (if you haven't already):
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx trigger.dev login
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This will open a browser window where you can log in with your Trigger.dev account and link your CLI.
|
|
38
|
+
|
|
39
|
+
Now you can deploy your tasks:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx trigger.dev deploy
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This should print out a success message and let you know a new version has been deployed:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
Trigger.dev (3.3.16)
|
|
49
|
+
------------------------------------------------------
|
|
50
|
+
┌ Deploying project
|
|
51
|
+
│
|
|
52
|
+
◇ Retrieved your account details for eric@trigger.dev
|
|
53
|
+
│
|
|
54
|
+
◇ Successfully built code
|
|
55
|
+
│
|
|
56
|
+
◇ Successfully deployed version 20250228.1
|
|
57
|
+
│
|
|
58
|
+
└ Version 20250228.1 deployed with 4 detected tasks
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Now if you visit your Trigger.dev dashboard you should see the new version deployed:
|
|
62
|
+
|
|
63
|
+

|
|
64
|
+
|
|
65
|
+
<Note>
|
|
66
|
+
Deploying consists of building your tasks and uploading them to the Trigger.dev cloud. This
|
|
67
|
+
process can take a few seconds to a few minutes depending on the size of your project.
|
|
68
|
+
</Note>
|
|
69
|
+
|
|
70
|
+
## Triggering deployed tasks
|
|
71
|
+
|
|
72
|
+
Once you have deployed your tasks, you can trigger tasks exactly the same way you did locally, but with the "PROD" API key:
|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+
Copy the API key from the dashboard and set the `TRIGGER_SECRET_KEY` environment variable, and then any tasks you trigger will run against the deployed version:
|
|
77
|
+
|
|
78
|
+
```txt .env
|
|
79
|
+
TRIGGER_SECRET_KEY="tr_prod_abc123"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Now you can trigger your tasks:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { myTask } from "./trigger/tasks";
|
|
86
|
+
|
|
87
|
+
await myTask.trigger({ foo: "bar" });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
See our [triggering tasks](/triggering) guide for more information.
|
|
91
|
+
|
|
92
|
+
## Versions
|
|
93
|
+
|
|
94
|
+
When you deploy your tasks, Trigger.dev creates a new version of all tasks in your project. A version is a snapshot of your tasks at a certain point in time. This ensures that tasks are not affected by changes to the code.
|
|
95
|
+
|
|
96
|
+
### Current version
|
|
97
|
+
|
|
98
|
+
When you deploy, the version number is automatically incremented, and the new version is set as the current version for that environment.
|
|
99
|
+
|
|
100
|
+
<Note>
|
|
101
|
+
A single environment (prod, staging, etc.) can only have a single "current" version at a time.
|
|
102
|
+
</Note>
|
|
103
|
+
|
|
104
|
+
The current version defines which version of the code new task runs will execute against. When a task run starts, it is locked to the current version. This ensures that the task run is not affected by changes to the code. Retries of the task run will also be locked to the original version.
|
|
105
|
+
|
|
106
|
+
<Note>
|
|
107
|
+
When you Replay a run in the dashboard we will create a new run, locked to the current version and
|
|
108
|
+
not necessarily the version of the original run.
|
|
109
|
+
</Note>
|
|
110
|
+
|
|
111
|
+
### Version locking
|
|
112
|
+
|
|
113
|
+
You can optionally specify the version when triggering a task using the `version` parameter. This is useful when you want to run a task against a specific version of the code:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
await myTask.trigger({ foo: "bar" }, { version: "20250228.1" });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
If you want to set a global version to run all tasks against, you can use the `TRIGGER_VERSION` environment variable:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
TRIGGER_VERSION=20250228.1
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Child tasks and auto-version locking
|
|
126
|
+
|
|
127
|
+
Trigger and wait functions version lock child task runs to the parent task run version. This ensures the results from child runs match what the parent task is expecting. If you don't wait then version locking doesn't apply.
|
|
128
|
+
|
|
129
|
+
| Trigger function | Parent task version | Child task version | isLocked |
|
|
130
|
+
| ----------------------- | ------------------- | ------------------ | -------- |
|
|
131
|
+
| `trigger()` | `20240313.2` | Current | No |
|
|
132
|
+
| `batchTrigger()` | `20240313.2` | Current | No |
|
|
133
|
+
| `triggerAndWait()` | `20240313.2` | `20240313.2` | Yes |
|
|
134
|
+
| `batchTriggerAndWait()` | `20240313.2` | `20240313.2` | Yes |
|
|
135
|
+
|
|
136
|
+
### Skipping promotion
|
|
137
|
+
|
|
138
|
+
When you deploy, the new version is automatically promoted be the current version. If you want to skip this promotion, you can use the `--skip-promotion` flag:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npx trigger.dev deploy --skip-promotion
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This will create a new deployment version but not promote it to the current version:
|
|
145
|
+
|
|
146
|
+

|
|
147
|
+
|
|
148
|
+
This allows you to deploy and test a new version without affecting new task runs. When you want to promote the version, you can do so from the CLI:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
npx trigger.dev promote 20250228.1
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Or from the dashboard:
|
|
155
|
+
|
|
156
|
+

|
|
157
|
+
|
|
158
|
+
To learn more about skipping promotion and how this enables atomic deployments, see our [Atomic deployment](/deployment/atomic-deployment) guide.
|
|
159
|
+
|
|
160
|
+
## Staging deploys
|
|
161
|
+
|
|
162
|
+
By default, the `deploy` command will deploy to the `prod` environment. If you want to deploy to a different environment, you can use the `--env` flag:
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
npx trigger.dev deploy --env staging
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
<Note>
|
|
169
|
+
If you are using the Trigger.dev Cloud, staging deploys are only available on the Hobby and Pro
|
|
170
|
+
plans.
|
|
171
|
+
</Note>
|
|
172
|
+
|
|
173
|
+
This will create an entirely new version of your tasks for the `staging` environment, with a new version number and an independent current version:
|
|
174
|
+
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
Now you can trigger tasks against the staging environment by setting the `TRIGGER_SECRET_KEY` environment variable to the staging API key:
|
|
178
|
+
|
|
179
|
+
```txt .env
|
|
180
|
+
TRIGGER_SECRET_KEY="tr_stg_abcd123"
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
For additional environments beyond `prod` and `staging`, you can use [preview branches](/deployment/preview-branches), which allow you to create isolated environments for each branch of your code.
|
|
184
|
+
|
|
185
|
+
## Local builds
|
|
186
|
+
|
|
187
|
+
By default we use a remote build provider to speed up builds. However, you can also force the build to happen locally on your machine using the `--force-local-build` flag:
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
npx trigger.dev deploy --force-local-build
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
<Tip>
|
|
194
|
+
Deploying with local builds can be a useful fallback in cases where our remote build provider is experiencing availability issues.
|
|
195
|
+
</Tip>
|
|
196
|
+
|
|
197
|
+
### System requirements
|
|
198
|
+
|
|
199
|
+
To use local builds, you need the following tools installed on your machine:
|
|
200
|
+
|
|
201
|
+
- Docker ([installation guide](https://docs.docker.com/get-started/get-docker))
|
|
202
|
+
- Docker Buildx ([installation guide](https://github.com/docker/buildx#installing))
|
|
203
|
+
|
|
204
|
+
## Environment variables
|
|
205
|
+
|
|
206
|
+
To add custom environment variables to your deployed tasks, you need to add them to your project in the Trigger.dev dashboard, or automatically sync them using our [syncEnvVars](/config/config-file#syncenvvars) or [syncVercelEnvVars](/config/config-file#syncvercelenvvars) build extensions.
|
|
207
|
+
|
|
208
|
+
For more information on environment variables, see our [environment variables](/deploy-environment-variables) guide.
|
|
209
|
+
|
|
210
|
+
## Troubleshooting
|
|
211
|
+
|
|
212
|
+
When things go wrong with your deployment, there are a few things you can do to diagnose the issue:
|
|
213
|
+
|
|
214
|
+
### Dry runs
|
|
215
|
+
|
|
216
|
+
You can do a "dry run" of the deployment to see what is built and uploaded without actually deploying:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
npx trigger.dev deploy --dry-run
|
|
220
|
+
|
|
221
|
+
# Dry run complete. View the built project at /<project path>/.trigger/tmp/<build dir>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The dry run will output the build directory where you can inspect the built tasks and dependencies. You can also compress this directory and send it to us if you need help debugging.
|
|
225
|
+
|
|
226
|
+
### Debug logs
|
|
227
|
+
|
|
228
|
+
You can run the deploy command with `--log-level debug` at the end. This will print out a lot of information about the deploy. If you can't figure out the problem from the information below please join [our Discord](https://trigger.dev/discord) and create a help forum post. Do NOT share the extended debug logs publicly as they might reveal private information about your project.
|
|
229
|
+
|
|
230
|
+
### Common issues
|
|
231
|
+
|
|
232
|
+
#### `Failed to build project image: Error building image`
|
|
233
|
+
|
|
234
|
+
There should be a link below the error message to the full build logs on your machine. Take a look at these to see what went wrong. Join [our Discord](https://trigger.dev/discord) and you share it privately with us if you can't figure out what's going wrong. Do NOT share these publicly as the verbose logs might reveal private information about your project.
|
|
235
|
+
|
|
236
|
+
Sometimes these errors are caused by upstream availability issues with our remote build provider. In this case, you can try deploying with a local build using the `--force-local-build` flag. Refer to the [Local builds](#local-builds) section for more information.
|
|
237
|
+
|
|
238
|
+
#### `Deployment encountered an error`
|
|
239
|
+
|
|
240
|
+
Usually there will be some useful guidance below this message. If you can't figure out what's going wrong then join [our Discord](https://trigger.dev/discord) and create a Help forum post with a link to your deployment.
|
|
241
|
+
|
|
242
|
+
#### `No loader is configured for ".node" files`
|
|
243
|
+
|
|
244
|
+
This happens because `.node` files are native code and can't be bundled like other packages. To fix this, add your package to [`build.external`](/config/config-file#external) in the `trigger.config.ts` file like this:
|
|
245
|
+
|
|
246
|
+
```ts trigger.config.ts
|
|
247
|
+
import { defineConfig } from "@trigger.dev/sdk";
|
|
248
|
+
|
|
249
|
+
export default defineConfig({
|
|
250
|
+
project: "<project ref>",
|
|
251
|
+
// Your other config settings...
|
|
252
|
+
build: {
|
|
253
|
+
external: ["your-node-package"],
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
<CorepackError />
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Preview branches"
|
|
3
|
+
description: "Create isolated environments for each branch of your code, allowing you to test changes before merging to production. You can create preview branches manually or automatically from your git branches."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## How to use preview branches
|
|
7
|
+
|
|
8
|
+
The preview environment is special – you create branches from it. The branches you create live under the preview environment and have all the features you're used to from other environments (like staging or production). That means you can trigger runs, have schedules, test them, use Realtime, etc.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
We recommend you automatically create a preview branch for each git branch when a Pull Request is opened and then archive it automatically when the PR is merged/closed.
|
|
13
|
+
|
|
14
|
+
The process to use preview branches looks like this:
|
|
15
|
+
|
|
16
|
+
1. Create a preview branch
|
|
17
|
+
2. Deploy to the preview branch (1+ times)
|
|
18
|
+
3. Trigger runs using your Preview API key (`TRIGGER_SECRET_KEY`) and the branch name (`TRIGGER_PREVIEW_BRANCH`).
|
|
19
|
+
4. Archive the preview branch when the branch is done.
|
|
20
|
+
|
|
21
|
+
There are two main ways to do this:
|
|
22
|
+
|
|
23
|
+
1. Automatically: using GitHub Actions (recommended).
|
|
24
|
+
2. Manually: in the dashboard and/or using the CLI.
|
|
25
|
+
|
|
26
|
+
### Limits on active preview branches
|
|
27
|
+
|
|
28
|
+
We restrict the number of active preview branches (per project). You can archive a preview branch at any time (automatically or manually) to unlock another slot – or you can upgrade your plan.
|
|
29
|
+
|
|
30
|
+
Once archived you can still view the dashboard for the branch but you can't trigger or execute runs (or other write operations).
|
|
31
|
+
|
|
32
|
+
This limit exists because each branch has an independent concurrency limit. For the Cloud product these are the limits:
|
|
33
|
+
|
|
34
|
+
| Plan | Active preview branches |
|
|
35
|
+
| ----- | ----------------------- |
|
|
36
|
+
| Free | 0 |
|
|
37
|
+
| Hobby | 5 |
|
|
38
|
+
| Pro | 20 (then paid for more) |
|
|
39
|
+
|
|
40
|
+
For full details see our [pricing page](https://trigger.dev/pricing).
|
|
41
|
+
|
|
42
|
+
## Triggering runs and using the SDK
|
|
43
|
+
|
|
44
|
+
Before we talk about how to deploy to preview branches, one important thing to understand is that you must set the `TRIGGER_PREVIEW_BRANCH` environment variable as well as the `TRIGGER_SECRET_KEY` environment variable.
|
|
45
|
+
|
|
46
|
+
When deploying to somewhere that supports `process.env` (like Node.js runtimes) you can just set the environment variables:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
TRIGGER_SECRET_KEY="tr_preview_1234567890"
|
|
50
|
+
TRIGGER_PREVIEW_BRANCH="your-branch-name"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
If you're deploying somewhere that doesn't support `process.env` (like some edge runtimes) you can manually configure the SDK:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { configure } from "@trigger.dev/sdk";
|
|
57
|
+
import { myTask } from "./trigger/myTasks";
|
|
58
|
+
|
|
59
|
+
configure({
|
|
60
|
+
secretKey: "tr_preview_1234567890", // WARNING: Never actually hardcode your secret key like this
|
|
61
|
+
previewBranch: "your-branch-name",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
async function triggerTask() {
|
|
65
|
+
await myTask.trigger({ userId: "1234" }); // Trigger a run in your-branch-name
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Triggering across multiple branches from one process
|
|
70
|
+
|
|
71
|
+
If a single process needs to trigger runs in several preview branches (or a mix of prod and preview), use `new TriggerClient({...})` for each target instead of mutating global config. Each instance owns its own auth and branch.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { TriggerClient } from "@trigger.dev/sdk";
|
|
75
|
+
|
|
76
|
+
const signupFlow = new TriggerClient({
|
|
77
|
+
accessToken: process.env.TRIGGER_PREVIEW_KEY,
|
|
78
|
+
previewBranch: "signup-flow",
|
|
79
|
+
});
|
|
80
|
+
const checkout = new TriggerClient({
|
|
81
|
+
accessToken: process.env.TRIGGER_PREVIEW_KEY,
|
|
82
|
+
previewBranch: "checkout-redesign",
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const payload = { to: "user@example.com" };
|
|
86
|
+
await Promise.all([
|
|
87
|
+
signupFlow.tasks.trigger("send-email", payload),
|
|
88
|
+
checkout.tasks.trigger("send-email", payload),
|
|
89
|
+
]);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See [Multiple SDK clients](/management/multiple-clients) for the full pattern.
|
|
93
|
+
|
|
94
|
+
## Preview branches with GitHub Actions (recommended)
|
|
95
|
+
|
|
96
|
+
This GitHub Action will:
|
|
97
|
+
|
|
98
|
+
1. Automatically create a preview branch for your Pull Request (if the branch doesn't already exist).
|
|
99
|
+
2. Deploy the preview branch.
|
|
100
|
+
3. Archive the preview branch when the Pull Request is merged/closed. This only works if your workflow runs on **closed** PRs (`types: [opened, synchronize, reopened, closed]`). If you omit `closed`, branches won't be archived automatically.
|
|
101
|
+
|
|
102
|
+
```yml .github/workflows/trigger-preview-branches.yml
|
|
103
|
+
name: Deploy to Trigger.dev (preview branches)
|
|
104
|
+
|
|
105
|
+
on:
|
|
106
|
+
pull_request:
|
|
107
|
+
types: [opened, synchronize, reopened, closed]
|
|
108
|
+
|
|
109
|
+
jobs:
|
|
110
|
+
deploy-preview:
|
|
111
|
+
runs-on: ubuntu-latest
|
|
112
|
+
steps:
|
|
113
|
+
- uses: actions/checkout@v4
|
|
114
|
+
|
|
115
|
+
- name: Use Node.js 20.x
|
|
116
|
+
uses: actions/setup-node@v4
|
|
117
|
+
with:
|
|
118
|
+
node-version: "20.x"
|
|
119
|
+
|
|
120
|
+
- name: Install dependencies
|
|
121
|
+
run: npm install
|
|
122
|
+
|
|
123
|
+
- name: Deploy preview branch
|
|
124
|
+
run: npx trigger.dev@latest deploy --env preview
|
|
125
|
+
env:
|
|
126
|
+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_ACCESS_TOKEN }}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For this workflow to work, you need to set the following secrets in your GitHub repository:
|
|
130
|
+
|
|
131
|
+
- `TRIGGER_ACCESS_TOKEN`: A Trigger.dev personal access token (they start with `tr_pat_`). [Learn how to create one and set it in GitHub](/github-actions#creating-a-personal-access-token).
|
|
132
|
+
|
|
133
|
+
Notice that the deploy command has `--env preview` at the end. We automatically detect the preview branch from the GitHub actions env var.
|
|
134
|
+
|
|
135
|
+
You can manually specify the branch using `--branch <branch-name>` in the deploy command, but this isn't required.
|
|
136
|
+
|
|
137
|
+
## Preview branches with the CLI (manual)
|
|
138
|
+
|
|
139
|
+
### Deploying a preview branch
|
|
140
|
+
|
|
141
|
+
Creating and deploying a preview branch manually is easy:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
npx trigger.dev@latest deploy --env preview
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
This will create and deploy a preview branch, automatically detecting the git branch. If for some reason the auto-detection doesn't work it will let you know and tell you do this:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
npx trigger.dev@latest deploy --env preview --branch your-branch-name
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Archiving a preview branch
|
|
154
|
+
|
|
155
|
+
You can manually archive a preview branch with the CLI:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
npx trigger.dev@latest preview archive
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Again we will try auto-detect the current branch. But you can specify the branch name with `--branch <branch-name>`.
|
|
162
|
+
|
|
163
|
+
## Creating and archiving preview branches from the dashboard
|
|
164
|
+
|
|
165
|
+
From the "Preview branches" page you can create a branch:
|
|
166
|
+
|
|
167
|
+

|
|
168
|
+

|
|
169
|
+
|
|
170
|
+
You can also archive a branch:
|
|
171
|
+
|
|
172
|
+

|
|
173
|
+
|
|
174
|
+
## Environment variables
|
|
175
|
+
|
|
176
|
+
You can set environment variables for "Preview" and they will get applied to all branches (existing and new). You can also set environment variables for a specific branch. If they are set for both then the branch-specific variables will take precedence.
|
|
177
|
+
|
|
178
|
+

|
|
179
|
+
|
|
180
|
+
These can be set manually in the dashboard, or automatically at deploy time using the [syncEnvVars()](/config/extensions/syncEnvVars) or [syncVercelEnvVars()](/config/extensions/syncEnvVars#syncvercelenvvars) build extensions.
|
|
181
|
+
|
|
182
|
+
### Sync environment variables
|
|
183
|
+
|
|
184
|
+
Full instructions are in the [syncEnvVars()](/config/extensions/syncEnvVars) documentation.
|
|
185
|
+
|
|
186
|
+
```ts trigger.config.ts
|
|
187
|
+
import { defineConfig } from "@trigger.dev/sdk";
|
|
188
|
+
// You will need to install the @trigger.dev/build package
|
|
189
|
+
import { syncEnvVars } from "@trigger.dev/build/extensions/core";
|
|
190
|
+
|
|
191
|
+
export default defineConfig({
|
|
192
|
+
//... other config
|
|
193
|
+
build: {
|
|
194
|
+
// This will automatically detect and sync environment variables
|
|
195
|
+
extensions: [
|
|
196
|
+
syncEnvVars(async (ctx) => {
|
|
197
|
+
// You can fetch env variables from a 3rd party service like Infisical, Hashicorp Vault, etc.
|
|
198
|
+
// The ctx.branch will be set if it's a preview deployment.
|
|
199
|
+
return await fetchEnvVars(ctx.environment, ctx.branch);
|
|
200
|
+
}),
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Sync Vercel environment variables
|
|
207
|
+
|
|
208
|
+
You need to set the `VERCEL_ACCESS_TOKEN`, `VERCEL_PROJECT_ID` and `VERCEL_TEAM_ID` environment variables. You can find these in the Vercel dashboard. Full instructions are in the [syncVercelEnvVars()](/config/extensions/syncEnvVars#syncvercelenvvars) documentation.
|
|
209
|
+
|
|
210
|
+
The extension will automatically detect a preview branch deploy from Vercel and sync the appropriate environment variables.
|
|
211
|
+
|
|
212
|
+
```ts trigger.config.ts
|
|
213
|
+
import { defineConfig } from "@trigger.dev/sdk";
|
|
214
|
+
// You will need to install the @trigger.dev/build package
|
|
215
|
+
import { syncVercelEnvVars } from "@trigger.dev/build/extensions/core";
|
|
216
|
+
|
|
217
|
+
export default defineConfig({
|
|
218
|
+
//... other config
|
|
219
|
+
build: {
|
|
220
|
+
// This will automatically detect and sync environment variables
|
|
221
|
+
extensions: [syncVercelEnvVars()],
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
```
|