Files
triggerdotdev--trigger.dev/apps/webapp/app/bootstrap.ts
nicktrn e7795a06ad Fix: fixes and prerequisites for v4 self-hosting (#2150)
* remove pgadmin

* remove V3_ENABLED

* v3 is always enabled

* enfore docker machine presets by default

* rename autoremove env var

* prefix more k8s-specific env vars

* same prefix for all docker settings

* improve profile switcher copy

* supervisor can load token from file

* optional webapp worker group bootstrap

* fix error message

* fix app origin fallback for otlp endpoint

* use pnpm cache for webapp docker builds

* increase default org and env concurrency limit to 100

* optional machine preset overrides

* improve s3 pre-signing errors

* fix DOCKER_ENFORCE_MACHINE_PRESETS bool coercion

* shard unit tests

* fix for s3-compatible services

* optional object store region

* Update apps/supervisor/src/workerToken.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* fix DEPLOY_REGISTRY_HOST example

* fix platform mock

* remove remaining v3Enabled refs

* fix error type.. bad bot

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-06-04 18:02:38 +01:00

76 lines
1.8 KiB
TypeScript

import { mkdir, writeFile } from "fs/promises";
import { prisma } from "./db.server";
import { env } from "./env.server";
import { WorkerGroupService } from "./v3/services/worker/workerGroupService.server";
import { dirname } from "path";
import { tryCatch } from "@trigger.dev/core";
export async function bootstrap() {
if (env.TRIGGER_BOOTSTRAP_ENABLED !== "1") {
return;
}
if (env.TRIGGER_BOOTSTRAP_WORKER_GROUP_NAME) {
const [error] = await tryCatch(createWorkerGroup());
if (error) {
console.error("Failed to create worker group", { error });
}
}
}
async function createWorkerGroup() {
const workerGroupName = env.TRIGGER_BOOTSTRAP_WORKER_GROUP_NAME;
const tokenPath = env.TRIGGER_BOOTSTRAP_WORKER_TOKEN_PATH;
const existingWorkerGroup = await prisma.workerInstanceGroup.findFirst({
where: {
name: workerGroupName,
},
});
if (existingWorkerGroup) {
console.warn(`[bootstrap] Worker group ${workerGroupName} already exists`);
return;
}
const service = new WorkerGroupService();
const { token, workerGroup } = await service.createWorkerGroup({
name: workerGroupName,
});
console.log(`
==========================
Trigger.dev Bootstrap - Worker Token
WARNING: This will only be shown once. Save it now!
Worker group:
${workerGroup.name}
Token:
${token.plaintext}
If using docker compose, set:
TRIGGER_WORKER_TOKEN=${token.plaintext}
${
tokenPath
? `Or, if using a file:
TRIGGER_WORKER_TOKEN=file://${tokenPath}`
: ""
}
==========================
`);
if (tokenPath) {
const dir = dirname(tokenPath);
await mkdir(dir, { recursive: true });
await writeFile(tokenPath, token.plaintext, {
mode: 0o600,
});
console.log(`[bootstrap] Worker token saved to ${tokenPath}`);
}
}