Skip to content

Commit c79bcc1

Browse files
committed
A bunch more doc updates after feedback
1 parent 463190d commit c79bcc1

17 files changed

+282
-303
lines changed

docs/config/config-file.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Some ones we recommend:
105105

106106
## Runtime
107107

108-
We currently only official support the `node` runtime, but you can try our expirimental `bun` runtime by setting the `runtime` option in your config file:
108+
We currently only officially support the `node` runtime, but you can try our experimental `bun` runtime by setting the `runtime` option in your config file:
109109

110110
```ts trigger.config.ts
111111
import { defineConfig } from "@trigger.dev/sdk/v3";
@@ -453,7 +453,11 @@ These environment variables are only used during the build process and are not e
453453

454454
</Note>
455455

456-
#### `audioWaveform`
456+
#### syncEnvVars
457+
458+
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.
459+
460+
#### audioWaveform
457461

458462
Previously, we installed [Audio Waveform](https://github.com/bbc/audiowaveform) in the build image. That's been moved to a build extension:
459463

@@ -469,7 +473,7 @@ export default defineConfig({
469473
});
470474
```
471475

472-
#### `ffmpeg`
476+
#### ffmpeg
473477

474478
You can add the `ffmpeg` build extension to your build process:
475479

@@ -528,7 +532,7 @@ export default defineConfig({
528532
});
529533
```
530534

531-
#### `aptGet`
535+
#### aptGet
532536

533537
You can install system packages into the deployed image using using the `aptGet` extension:
534538

docs/deploy-environment-variables.mdx

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ You can use our SDK to get and manipulate environment variables. You can also ea
7474

7575
We have a complete set of SDK functions (and REST API) you can use to directly manipulate environment variables.
7676

77-
| Function | Description |
78-
| ----------------------------------------------------- | ----------------------------------------------------------- |
77+
| Function | Description |
78+
| -------------------------------------------------- | ----------------------------------------------------------- |
7979
| [envvars.list()](/management/envvars/list) | List all environment variables |
8080
| [envvars.upload()](/management/envvars/import) | Upload multiple env vars. You can override existing values. |
8181
| [envvars.create()](/management/envvars/create) | Create a new environment variable |
@@ -85,93 +85,91 @@ We have a complete set of SDK functions (and REST API) you can use to directly m
8585

8686
### Sync env vars from another service
8787

88-
You could use the SDK functions above but it's much easier to use our `resolveEnvVars` function in your `trigger.config` file.
88+
You could use the SDK functions above but it's much easier to use our `syncEnvVars` build extension in your `trigger.config` file.
8989

90-
In this example we're using env vars from [Infisical](https://infisical.com).
90+
<Note>
91+
To use the `syncEnvVars` build extension, you should first install the `@trigger.dev/build`
92+
package into your devDependencies.
93+
</Note>
9194

92-
```ts /trigger.config.ts
93-
import type { TriggerConfig, ResolveEnvironmentVariablesFunction } from "@trigger.dev/sdk/v3";
94-
95-
//This runs when you run the deploy command or the dev command
96-
export const resolveEnvVars: ResolveEnvironmentVariablesFunction = async ({
97-
//the project ref (starting with "proj_")
98-
projectRef,
99-
//any existing env vars from a .env file or Trigger.dev
100-
env,
101-
//"dev", "staging", or "prod"
102-
environment,
103-
}) => {
104-
//the existing environment variables from Trigger.dev (or your local .env file)
105-
if (env.INFISICAL_CLIENT_ID === undefined || env.INFISICAL_CLIENT_SECRET === undefined) {
106-
//returning undefined won't modify the existing env vars
107-
return;
108-
}
109-
110-
const client = new InfisicalClient({
111-
clientId: env.INFISICAL_CLIENT_ID,
112-
clientSecret: env.INFISICAL_CLIENT_SECRET,
113-
});
114-
115-
const secrets = await client.listSecrets({
116-
environment,
117-
projectId: env.INFISICAL_PROJECT_ID!,
118-
});
119-
120-
return {
121-
variables: secrets.map((secret) => ({
122-
name: secret.secretKey,
123-
value: secret.secretValue,
124-
})),
125-
// this defaults to true
126-
// override: true,
127-
};
128-
};
95+
In this example we're using env vars from [Infisical](https://infisical.com).
12996

130-
//the rest of your config file
131-
export const config: TriggerConfig = {
132-
project: "proj_1234567890",
133-
//etc
134-
};
97+
```ts trigger.config.ts
98+
import { defineConfig } from "@trigger.dev/sdk/v3";
99+
import { syncEnvVars } from "@trigger.dev/build/extensions/core";
100+
import { InfisicalClient } from "@infisical/sdk";
101+
102+
export default defineConfig({
103+
build: {
104+
extensions: [
105+
syncEnvVars(async (ctx) => {
106+
const client = new InfisicalClient({
107+
clientId: process.env.INFISICAL_CLIENT_ID,
108+
clientSecret: process.env.INFISICAL_CLIENT_SECRET,
109+
});
110+
111+
const secrets = await client.listSecrets({
112+
environment: ctx.environment,
113+
projectId: process.env.INFISICAL_PROJECT_ID!,
114+
});
115+
116+
return secrets.map((secret) => ({
117+
name: secret.secretKey,
118+
value: secret.secretValue,
119+
}));
120+
}),
121+
],
122+
},
123+
});
135124
```
136125

137-
#### Local development
138-
139-
When you [develop locally](/cli-dev) `resolveEnvVars()` will inject the env vars from [Infisical](https://infisical.com) into your local `process.env`.
140-
141126
#### Deploy
142127

143128
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.
144129

145130
This means that you need to redeploy your Trigger.dev tasks if you change the environment variables in [Infisical](https://infisical.com).
146131

147-
### The variables return type
132+
<Note>
133+
The `process.env.INFISICAL_CLIENT_ID`, `process.env.INFISICAL_CLIENT_SECRET` and
134+
`process.env.INFISICAL_PROJECT_ID` will need to be supplied to the `deploy` CLI command. You can
135+
do this via the `--env-file .env` flag or by setting them as environment variables in your
136+
terminal.
137+
</Note>
138+
139+
#### Dev
148140

149-
You can return `variables` as an object with string keys and values, or an array of names + values.
141+
`syncEnvVars` does not have any effect when running the `dev` command locally. If you want to inject environment variables from another service into your local environment you can do so via a `.env` file or just supplying them as environment variables in your terminal. Most services will have a CLI tool that allows you to run a command with environment variables set:
142+
143+
```sh
144+
infisical run -- npx trigger.dev@latest dev
145+
```
146+
147+
Any environment variables set in the CLI command will be available to your local Trigger.dev tasks.
148+
149+
### The syncEnvVars callback return type
150+
151+
You can return env vars as an object with string keys and values, or an array of names + values.
150152

151153
```ts
152154
return {
153-
variables: {
154-
MY_ENV_VAR: "my value",
155-
MY_OTHER_ENV_VAR: "my other value",
156-
},
155+
MY_ENV_VAR: "my value",
156+
MY_OTHER_ENV_VAR: "my other value",
157157
};
158158
```
159159

160160
or
161161

162162
```ts
163-
return {
164-
variables: [
165-
{
166-
name: "MY_ENV_VAR",
167-
value: "my value",
168-
},
169-
{
170-
name: "MY_OTHER_ENV_VAR",
171-
value: "my other value",
172-
},
173-
],
174-
};
163+
return [
164+
{
165+
name: "MY_ENV_VAR",
166+
value: "my value",
167+
},
168+
{
169+
name: "MY_OTHER_ENV_VAR",
170+
value: "my other value",
171+
},
172+
];
175173
```
176174

177175
This should mean that for most secret services you won't need to convert the data into a different format.
@@ -184,11 +182,11 @@ Securely pass a Google credential JSON file to your Trigger.dev task using envir
184182

185183
<Step title="Convert the Google credential file to base64">
186184

187-
In your terminal, run the following command and copy the resulting base64 string:
185+
In your terminal, run the following command and copy the resulting base64 string:
188186

189-
```
190-
base64 path/to/your/service-account-file.json
191-
```
187+
```
188+
base64 path/to/your/service-account-file.json
189+
```
192190

193191
</Step>
194192

@@ -207,13 +205,15 @@ GOOGLE_CREDENTIALS_BASE64="<your base64 string>"
207205
Add the following code to your Trigger.dev task:
208206

209207
```ts
210-
import { google } from 'googleapis';
208+
import { google } from "googleapis";
211209

212-
const credentials = JSON.parse(Buffer.from(process.env.GOOGLE_CREDENTIALS_BASE64, 'base64').toString('utf8'));
210+
const credentials = JSON.parse(
211+
Buffer.from(process.env.GOOGLE_CREDENTIALS_BASE64, "base64").toString("utf8")
212+
);
213213

214214
const auth = new google.auth.GoogleAuth({
215215
credentials,
216-
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
216+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
217217
});
218218

219219
const client = await auth.getClient();
@@ -227,4 +227,4 @@ You can now use the `client` object to make authenticated requests to Google API
227227

228228
</Step>
229229

230-
</Steps>
230+
</Steps>

docs/github-actions.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ If you already have a GitHub action file, you can just add the final step "🚀
9999

100100
## Version pinning
101101

102-
The CLI and `@trigger.dev/*` package versions need to be in sync, otherwise there will be errors and unpredictable behavior. Hence, the `deploy` command will automatically fail during CI on any version mismatches.
102+
The CLI and `@trigger.dev/*` package versions need to be in sync with the `trigger.dev` CLI, otherwise there will be errors and unpredictable behavior. Hence, the `deploy` command will automatically fail during CI on any version mismatches.
103103
Tip: add the deploy command to your `package.json` file to keep versions managed in the same place. For example:
104104

105105
```json
106106
{
107107
"scripts": {
108-
"deploy:trigger-prod": "npx [email protected]-beta.34 deploy",
109-
"deploy:trigger": "npx [email protected]-beta.34 deploy --env staging"
108+
"deploy:trigger-prod": "npx [email protected] deploy",
109+
"deploy:trigger": "npx [email protected] deploy --env staging"
110110
}
111111
}
112112
```

docs/guides/bun.mdx

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: "Bun guide"
3+
sidebarTitle: "Bun"
4+
description: "This guide will show you how to setup Trigger.dev with Bun"
5+
icon: "js"
6+
---
7+
8+
import Prerequisites from "/snippets/framework-prerequisites.mdx";
9+
import CliRunTestStep from "/snippets/step-run-test.mdx";
10+
import CliViewRunStep from "/snippets/step-view-run.mdx";
11+
12+
We now have experimental support for Bun. This guide will show you have to setup Trigger.dev in your existing Bun project, test an example task, and view the run.
13+
14+
<Warn>
15+
The trigger.dev CLI does not yet support Bun. So you will need to run the CLI using Node.js. But
16+
Bun will still be used to execute your tasks, even in the `dev` environment.
17+
</Warn>
18+
19+
<Prerequisites framework="Bun" />
20+
21+
## Initial setup
22+
23+
<Steps>
24+
<Step title="Run the CLI `init` command">
25+
26+
The easiest way to get started is to use the CLI. It will add Trigger.dev to your existing project, create a `/trigger` folder and give you an example task.
27+
28+
Run this command in the root of your project to get started:
29+
30+
<CodeGroup>
31+
32+
```bash npm
33+
npx trigger.dev@latest init --runtime bun
34+
```
35+
36+
```bash pnpm
37+
pnpm dlx trigger.dev@latest init --runtime bun
38+
```
39+
40+
```bash yarn
41+
yarn dlx trigger.dev@latest init --runtime bun
42+
```
43+
44+
</CodeGroup>
45+
46+
It will do a few things:
47+
48+
1. Log you into the CLI if you're not already logged in.
49+
2. Create a `trigger.config.ts` file in the root of your project.
50+
3. Ask where you'd like to create the `/trigger` directory.
51+
4. Create the `/src/trigger` directory with an example task, `/src/trigger/example.[ts/js]`.
52+
53+
Install the "Hello World" example task when prompted. We'll use this task to test the setup.
54+
55+
</Step>
56+
57+
<Step title="Update example.ts to use Bun">
58+
59+
Open the `/src/trigger/example.ts` file and replace the contents with the following:
60+
61+
```ts example.ts
62+
import { Database } from "bun:sqlite";
63+
import { task } from "@trigger.dev/sdk/v3";
64+
65+
export const bunTask = task({
66+
id: "bun-task",
67+
run: async (payload: { query: string }) => {
68+
const db = new Database(":memory:");
69+
const query = db.query("select 'Hello world' as message;");
70+
console.log(query.get()); // => { message: "Hello world" }
71+
72+
return {
73+
message: "Query executed",
74+
};
75+
},
76+
});
77+
78+
```
79+
80+
</Step>
81+
82+
<Step title="Run the CLI `dev` command">
83+
84+
The CLI `dev` command runs a server for your tasks. It watches for changes in your `/trigger` directory and communicates with the Trigger.dev platform to register your tasks, perform runs, and send data back and forth.
85+
86+
It can also update your `@trigger.dev/*` packages to prevent version mismatches and failed deploys. You will always be prompted first.
87+
88+
<CodeGroup>
89+
90+
```bash npm
91+
npx trigger.dev@latest dev
92+
```
93+
94+
```bash pnpm
95+
pnpm dlx trigger.dev@latest dev
96+
```
97+
98+
```bash yarn
99+
yarn dlx trigger.dev@latest dev
100+
```
101+
102+
</CodeGroup>
103+
104+
</Step>
105+
106+
<CliRunTestStep />
107+
<CliViewRunStep />
108+
109+
</Steps>
110+
111+
## Known issues
112+
113+
- Certain OpenTelemetry instrumentation will not work with Bun, because Bun does not support Node's `register` hook. This means that some libraries that rely on this hook will not work with Bun.

0 commit comments

Comments
 (0)