Skip to content

Commit 8d1e416

Browse files
authored
v3: self-hosting support for latest packages (#1319)
* display --profile flag after init if used * add containerfile debug logs * log all indexing errors in case of connection issues * specify dockerfile syntax version * add network flag for self-hosting * move all self-hosting tags to latest * add self-hosting update section * manual setup subsection * registry flag implies push * add changeset
1 parent 4adc773 commit 8d1e416

File tree

10 files changed

+90
-29
lines changed

10 files changed

+90
-29
lines changed

.changeset/metal-geckos-pretend.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
- Improve index error logging
6+
- Add network flag for self-hosted deploys
7+
- Fix checksum flag on some docker versions
8+
- Add Containerfile debug logs

docs/github-actions.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ jobs:
181181
TRIGGER_API_URL: ${{ secrets.TRIGGER_API_URL }}
182182
# deploy with additional flags
183183
run: |
184-
npx trigger.dev@beta deploy --self-hosted --push
184+
npx trigger.dev@latest deploy --self-hosted --push
185185
```
186186

187187
</CodeGroup>

docs/open-source-self-hosting.mdx

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ title: "Self-hosting"
33
description: "You can self-host Trigger.dev on your own infrastructure."
44
---
55

6-
<Warning>Self-hosting does not support the latest CLI yet, you will have to continue using the `beta` tag for now.</Warning>
7-
86
## Overview
97

108
<Frame>
@@ -94,7 +92,7 @@ git checkout v3
9492
./start.sh # hint: you can append -d to run in detached mode
9593
```
9694

97-
### Manual setup
95+
#### Manual
9896

9997
Alternatively, you can follow these manual steps after cloning the docker repo:
10098

@@ -176,7 +174,7 @@ docker login -u <your_dockerhub_username>
176174
5. You can now deploy v3 projects using the CLI with these flags:
177175

178176
```
179-
npx trigger.dev@beta deploy --self-hosted --push
177+
npx trigger.dev@latest deploy --self-hosted --push
180178
```
181179

182180
## Part 2: Split services
@@ -286,12 +284,44 @@ echo "FORCE_CHECKPOINT_SIMULATION=0" >> .env
286284
./stop.sh worker && ./start.sh worker
287285
```
288286

289-
## Telemetry
287+
## Updating
290288

291-
By default, the Trigger.dev webapp sends telemetry data to our servers. This data is used to improve the product and is not shared with third parties. If you would like to opt-out of this, you can set the `TRIGGER_TELEMETRY_DISABLED` environment variable in your `.env` file. The value doesn't matter, it just can't be empty. For example:
289+
Once you have everything set up, you will periodically want to update your Docker images. You can easily do this by running the update script and restarting your services:
292290

293291
```bash
294-
TRIGGER_TELEMETRY_DISABLED=1
292+
./update.sh
293+
./stop.sh && ./start.sh
294+
```
295+
296+
Sometimes, we will make more extensive changes that require pulling updated compose files, scripts, etc from our docker repo:
297+
298+
```bash
299+
git pull
300+
./stop.sh && ./start.sh
301+
```
302+
303+
Occasionally, you may also have to update your `.env` file, but we will try to keep these changes to a minimum. Check the `.env.example` file for new variables.
304+
305+
### From beta
306+
307+
If you're coming from the beta CLI package images, you will need to:
308+
- **Pull changes from our docker repo.** We've added a new container for [Electric](https://github.com/electric-sql/electric) and made some other improvements.
309+
310+
```bash
311+
# wherever you cloned the docker repo
312+
git pull && ./stop.sh && ./start.sh
313+
```
314+
315+
## Version locking
316+
317+
There are several reasons to lock the version of your Docker images:
318+
- **Backwards compatibility.** We try our best to maintain compatibility with older CLI versions, but it's not always possible. If you don't want to update your CLI, you can lock your Docker images to that specific version.
319+
- **Ensuring full feature support.** Sometimes, new CLI releases will also require new or updated platform features. Running unlocked images can make any issues difficult to debug. Using a specific tag can help here as well.
320+
321+
By default, the images will point at the latest versioned release via the `v3` tag. You can override this by specifying a different tag in your `.env` file. For example:
322+
323+
```bash
324+
TRIGGER_IMAGE_TAG=v3.0.5
295325
```
296326

297327
## CLI usage
@@ -303,7 +333,7 @@ This section highlights some of the CLI commands and options that are useful whe
303333
To avoid being redirected to the [Trigger.dev Cloud](https://cloud.trigger.dev) login page when using the CLI, you can specify the URL of your self-hosted instance with the `--api-url` or `-a` flag. For example:
304334

305335
```bash
306-
npx trigger.dev@beta login -a http://trigger.example.com
336+
npx trigger.dev@latest login -a http://trigger.example.com
307337
```
308338

309339
Once you've logged in, the CLI will remember your login details and you won't need to specify the URL again with other commands.
@@ -313,38 +343,38 @@ Once you've logged in, the CLI will remember your login details and you won't ne
313343
You can specify a custom profile when logging in. This allows you to easily use the CLI with our cloud product and your self-hosted instance at the same time. For example:
314344

315345
```
316-
npx trigger.dev@beta login -a http://trigger.example.com --profile my-profile
346+
npx trigger.dev@latest login -a http://trigger.example.com --profile my-profile
317347
```
318348

319349
You can then use this profile with other commands:
320350

321351
```
322-
npx trigger.dev@beta dev --profile my-profile
352+
npx trigger.dev@latest dev --profile my-profile
323353
```
324354

325355
To list all your profiles, use the `list-profiles` command:
326356

327357
```
328-
npx trigger.dev@beta list-profiles
358+
npx trigger.dev@latest list-profiles
329359
```
330360

331361
#### Verify login
332362

333363
It can be useful to check you have successfully logged in to the correct instance. You can do this with the `whoami` command, which will also show the API URL:
334364

335365
```bash
336-
npx trigger.dev@beta whoami
366+
npx trigger.dev@latest whoami
337367

338368
# with a custom profile
339-
npx trigger.dev@beta whoami --profile my-profile
369+
npx trigger.dev@latest whoami --profile my-profile
340370
```
341371

342372
### Deploy
343373

344374
On [Trigger.dev Cloud](https://cloud.trigger.dev), we build deployments remotely and push those images for you. When self-hosting you will have to do that locally yourself. This can be done with the `--self-hosted` and `--push` flags. For example:
345375

346376
```
347-
npx trigger.dev@beta deploy --self-hosted --push
377+
npx trigger.dev@latest deploy --self-hosted --push
348378
```
349379

350380
### CI / GitHub Actions
@@ -353,3 +383,12 @@ When running the CLI in a CI environment, your login profiles won't be available
353383
variables to point at your self-hosted instance and authenticate.
354384

355385
For more detailed instructions, see the [GitHub Actions guide](/github-actions).
386+
387+
388+
## Telemetry
389+
390+
By default, the Trigger.dev webapp sends telemetry data to our servers. This data is used to improve the product and is not shared with third parties. If you would like to opt-out of this, you can set the `TRIGGER_TELEMETRY_DISABLED` environment variable in your `.env` file. The value doesn't matter, it just can't be empty. For example:
391+
392+
```bash
393+
TRIGGER_TELEMETRY_DISABLED=1
394+
```

docs/snippets/cli-commands-deploy.mdx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,37 @@ These options are available on most commands.
8181

8282
These options are typically used when [self-hosting](/open-source-self-hosting) or for local development.
8383

84-
<ParamField body="Skip deploying the image" type="--skip-deploy | -D">
85-
Load the built image into your local docker.
86-
</ParamField>
87-
8884
<ParamField body="Self-hosted (builds locally)" type="--self-hosted">
8985
Builds and loads the image using your local docker. Use the `--registry` option to specify the
9086
registry to push the image to when using `--self-hosted`, or just use `--push` to push to the
9187
default registry.
9288
</ParamField>
9389

90+
<ParamField body="Skip deploying the image" type="--skip-deploy | -D">
91+
Load the built image into your local docker.
92+
</ParamField>
93+
9494
<ParamField body="Load image" type="--load-image">
9595
Loads the image into your local docker after building it.
9696
</ParamField>
9797

9898
<ParamField body="Registry" type="--registry">
99-
Specify the registry to push the image to when using `--self-hosted`.
99+
Specify the registry to push the image to when using `--self-hosted`. Will automatically enable `--push`.
100100
</ParamField>
101101

102102
<ParamField body="Push image" type="--push">
103-
When using the --self-hosted flag, push the image to the registry.
103+
When using the `--self-hosted` flag, push the image to the registry.
104104
</ParamField>
105105

106106
<ParamField body="Namespace" type="--namepsace">
107107
The namespace to use when pushing the image to the registry. For example, if pushing to Docker
108108
Hub, the namespace is your Docker Hub username.
109109
</ParamField>
110110

111+
<ParamField body="Network" type="--network">
112+
The networking mode for RUN instructions when using `--self-hosted`.
113+
</ParamField>
114+
111115
## Examples
112116

113117
### Push to Docker Hub (self-hosted)
@@ -118,7 +122,6 @@ An example of deploying to Docker Hub when using a self-hosted setup:
118122
npx trigger.dev@latest deploy \
119123
--self-hosted \
120124
--load-image \
121-
--push \
122125
--registry docker.io \
123126
--namespace mydockerhubusername
124127
```

docs/upgrading-beta.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ You can now specify a custom registry and namespace when deploying via a self-ho
412412
npx trigger.dev@latest deploy \
413413
--self-hosted \
414414
--load-image \
415-
--push \
416415
--registry docker.io \
417416
--namespace mydockerhubusername
418417
```

packages/cli-v3/src/build/buildWorker.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,10 @@ async function writeContainerfile(outputPath: string, buildManifest: BuildManife
223223
indexScript: buildManifest.indexControllerEntryPoint,
224224
});
225225

226-
await writeFile(join(outputPath, "Containerfile"), containerfile);
226+
const containerfilePath = join(outputPath, "Containerfile");
227+
228+
logger.debug("Writing Containerfile", { containerfilePath });
229+
logger.debug(containerfile);
230+
231+
await writeFile(containerfilePath, containerfile);
227232
}

packages/cli-v3/src/commands/deploy.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const DeployCommandOptions = CommonCommandOptions.extend({
5555
skipUpdateCheck: z.boolean().default(false),
5656
noCache: z.boolean().default(false),
5757
envFile: z.string().optional(),
58+
network: z.enum(["default", "none", "host"]).optional(),
5859
});
5960

6061
type DeployCommandOptions = z.infer<typeof DeployCommandOptions>;
@@ -144,6 +145,7 @@ export function configureDeployCommand(program: Command) {
144145
"If provided, will save logs even for successful builds"
145146
).hideHelp()
146147
)
148+
.option("--network <mode>", "The networking mode for RUN instructions when using --self-hosted")
147149
.action(async (path, options) => {
148150
await handleTelemetry(async () => {
149151
await printStandloneInitialBanner(true);
@@ -349,6 +351,7 @@ async function _deployCommand(dir: string, options: DeployCommandOptions) {
349351
authAccessToken: authorization.auth.accessToken,
350352
compilationPath: destination.path,
351353
buildEnvVars: buildManifest.build.env,
354+
network: options.network,
352355
});
353356

354357
logger.debug("Build result", buildResult);

packages/cli-v3/src/commands/init.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,7 @@ async function _initCommand(dir: string, options: InitCommandOptions) {
194194
log.info("Next steps:");
195195
log.info(
196196
` 1. To start developing, run ${chalk.green(
197-
`npx trigger.dev@${options.tag} dev${
198-
options.apiUrl === CLOUD_API_URL ? "" : ` -a ${options.apiUrl}`
199-
}`
197+
`npx trigger.dev@${options.tag} dev${options.profile ? "" : ` --profile ${options.profile}`}`
200198
)} in your project directory`
201199
);
202200
log.info(` 2. Visit your ${projectDashboard} to view your newly created tasks.`);

packages/cli-v3/src/deploy/buildImage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface BuildImageOptions {
1414
// Self-hosted specific options
1515
push: boolean;
1616
registry?: string;
17+
network?: string;
1718

1819
// Non-self-hosted specific options
1920
loadImage?: boolean;
@@ -84,6 +85,7 @@ export async function buildImage(options: BuildImageOptions) {
8485
apiUrl,
8586
apiKey,
8687
buildEnvVars,
88+
network: options.network,
8789
});
8890
}
8991

@@ -277,6 +279,7 @@ interface SelfHostedBuildImageOptions {
277279
noCache?: boolean;
278280
extraCACerts?: string;
279281
buildEnvVars?: Record<string, string | undefined>;
282+
network?: string;
280283
}
281284

282285
async function selfHostedBuildImage(
@@ -295,6 +298,7 @@ async function selfHostedBuildImage(
295298
options.noCache ? "--no-cache" : undefined,
296299
"--platform",
297300
options.buildPlatform,
301+
...(options.network ? ["--network", options.network] : []),
298302
"--build-arg",
299303
`TRIGGER_PROJECT_ID=${options.projectId}`,
300304
"--build-arg",
@@ -458,7 +462,7 @@ async function generateBunContainerfile(options: GenerateContainerfileOptions) {
458462
" "
459463
);
460464

461-
return `
465+
return `# syntax=docker/dockerfile:1
462466
FROM imbios/bun-node:22-debian AS base
463467
464468
${baseInstructions}
@@ -563,7 +567,7 @@ async function generateNodeContainerfile(options: GenerateContainerfileOptions)
563567
" "
564568
);
565569

566-
return `
570+
return `# syntax=docker/dockerfile:1
567571
FROM node:21-bookworm-slim@sha256:99afef5df7400a8d118e0504576d32ca700de5034c4f9271d2ff7c91cc12d170 AS base
568572
569573
${baseInstructions}

packages/cli-v3/src/entryPoints/deploy-index-controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ async function indexDeployment({
104104
} catch (error) {
105105
const serialiedIndexError = serializeIndexingError(error, stderr.join("\n"));
106106

107+
console.error("Failed to index deployment", serialiedIndexError);
108+
107109
await cliApiClient.failDeployment(deploymentId, { error: serialiedIndexError });
108110

109111
process.exit(1);

0 commit comments

Comments
 (0)