-
Notifications
You must be signed in to change notification settings - Fork 242
Expand file tree
/
Copy pathtrigger.config.ts
More file actions
172 lines (162 loc) · 5.07 KB
/
Copy pathtrigger.config.ts
File metadata and controls
172 lines (162 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import { existsSync, readdirSync, readFileSync } from "node:fs";
import {
additionalPackages,
aptGet,
syncEnvVars,
} from "@trigger.dev/build/extensions/core";
import { defineConfig } from "@trigger.dev/sdk/v3";
import { fetchInfisicalSecretsFromEnv } from "./server/src/external/infisical/fetchInfisicalSecrets.js";
// Bun requires every configured workspace to contain a package.json, even
// though Trigger bundles workspace code and only installs external packages.
const rootPackageJson = JSON.parse(readFileSync("package.json", "utf-8")) as {
workspaces: string[] | { packages: string[] };
};
const workspacePatterns = Array.isArray(rootPackageJson.workspaces)
? rootPackageJson.workspaces
: rootPackageJson.workspaces.packages;
const expandWorkspacePattern = (pattern: string): string[] => {
if (!pattern.includes("*")) {
return [pattern];
}
const baseDir = pattern.slice(0, pattern.indexOf("*")).replace(/\/$/, "");
return readdirSync(baseDir, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => `${baseDir}/${entry.name}`);
};
const workspacePackageDirs = workspacePatterns
.flatMap(expandWorkspacePattern)
.filter((dir) => existsSync(`${dir}/package.json`))
.sort();
const workspacePackageStubs = workspacePackageDirs.map((dir) => {
const packageJson = JSON.parse(
readFileSync(`${dir}/package.json`, "utf-8"),
) as { name?: string };
if (!packageJson.name) {
throw new Error(`Workspace package ${dir} is missing a name`);
}
return {
dir,
contents: JSON.stringify({ name: packageJson.name, private: true }),
};
});
const listFilesRecursive = ({ dir }: { dir: string }): string[] => {
if (!existsSync(dir)) return [];
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const path = `${dir}/${entry.name}`;
if (entry.isDirectory()) return listFilesRecursive({ dir: path });
return entry.isFile() ? [path] : [];
});
};
// Trigger copies patchedDependencies in package.json but only COPY package.json
// before bun install, so the patch files must already exist in the base image.
const bunPatchInstallCommands = listFilesRecursive({ dir: "patches" }).map(
(path) => {
const encoded = readFileSync(path).toString("base64");
return `mkdir -p "$(dirname -- '${path}')" && printf '%s' '${encoded}' | base64 -d > '${path}'`;
},
);
export default defineConfig({
project: "proj_cwiutfmpdzfcshxevkok",
runtime: "bun",
logLevel: "log",
maxDuration: 3600,
retries: {
enabledInDev: true,
default: {
maxAttempts: 3,
minTimeoutInMs: 1000,
maxTimeoutInMs: 10000,
factor: 2,
randomize: true,
},
},
dirs: [
"server/src/trigger",
"server/src/internal/billing/v2/actions/batchTransition/tasks",
],
build: {
// Native / heavy deps stay external — bundling them inflates the deploy
// and breaks platform-specific binaries (pg, ioredis, etc.).
external: [
"@aws-sdk/client-s3",
"@duckdb/node-api",
"@google-cloud/bigquery",
"ioredis",
"pino",
"@axiomhq/pino",
"drizzle-orm",
"postgres",
"pg",
"zod",
"@duckdb/node-api",
"@duckdb/node-bindings",
"@duckdbfan/drizzle-duckdb",
],
extensions: [
{
name: "monorepo-workspace-manifests",
onBuildComplete: (context) => {
if (context.target !== "deploy") {
return;
}
context.addLayer({
id: "monorepo-workspace-manifests",
image: {
instructions: [
"WORKDIR /app",
`RUN mkdir -p ${workspacePackageDirs.join(" ")} && ${workspacePackageStubs.map(({ dir, contents }) => `printf '${contents}' > ${dir}/package.json`).join(" && ")} && chown -R bun:bun /app`,
],
},
});
if (bunPatchInstallCommands.length > 0) {
context.addLayer({
id: "bun-patched-dependencies",
image: {
instructions: [
"WORKDIR /app",
`RUN ${bunPatchInstallCommands.join(" && ")} && chown -R bun:bun /app/patches`,
],
},
});
}
},
},
// Server runtime imports `*.lua` as raw text via Bun's loader. esbuild
// (used by the trigger build) doesn't see bunfig — register a plugin
// that reads .lua files as text so the same imports work post-bundle.
{
name: "lua-text-loader",
onBuildStart: async (context) => {
context.registerPlugin({
name: "lua-text-loader-plugin",
setup(build) {
build.onLoad({ filter: /\.lua$/ }, async (args) => {
const { readFileSync } = await import("node:fs");
return {
contents: readFileSync(args.path, "utf-8"),
loader: "text",
};
});
},
});
},
},
aptGet({ packages: ["pkg-config", "liblzma-dev"] }),
additionalPackages({
packages: [
"@axiomhq/pino",
"@duckdb/node-api@1.5.5-r.4",
"postgres",
"pg",
"drizzle-orm",
"ioredis",
"zod",
],
}),
// In DEV: `bun d` / `bun dw` run `bunx trigger.dev dev --branch <user-git>`
// under Infisical, with TRIGGER_DEV_BRANCH set so the server SDK and
// CLI share an isolated queue. `syncEnvVars` only runs at DEPLOY time.
syncEnvVars(async (ctx) => fetchInfisicalSecretsFromEnv(ctx.env)),
],
},
});