Skip to content

Commit e337b21

Browse files
committed
Add a postInstall option to allow running scripts after dependencies have been installed in deployed images
1 parent 9e53829 commit e337b21

File tree

7 files changed

+46
-4
lines changed

7 files changed

+46
-4
lines changed

.changeset/rare-lamps-promise.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/core": patch
4+
---
5+
6+
Add a postInstall option to allow running scripts after dependencies have been installed in deployed images

packages/cli-v3/src/Containerfile.prod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ COPY --chown=node:node . .
1919
USER node
2020
RUN npm ci --no-fund --no-audit && npm cache clean --force
2121

22+
__POST_INSTALL__
23+
2224
# Development or production stage builds upon the base stage
2325
FROM base AS final
2426

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,19 @@ async function compileProject(
13251325

13261326
// Write the Containerfile to /tmp/dir/Containerfile
13271327
const containerFilePath = join(cliRootPath(), "Containerfile.prod");
1328-
// Copy the Containerfile to /tmp/dir/Containerfile
1329-
await copyFile(containerFilePath, join(tempDir, "Containerfile"));
1328+
1329+
let containerFileContents = readFileSync(containerFilePath, "utf-8");
1330+
1331+
if (config.postInstall) {
1332+
containerFileContents = containerFileContents.replace(
1333+
"__POST_INSTALL__",
1334+
`RUN ${config.postInstall}`
1335+
);
1336+
} else {
1337+
containerFileContents = containerFileContents.replace("__POST_INSTALL__", "");
1338+
}
1339+
1340+
await writeFile(join(tempDir, "Containerfile"), containerFileContents);
13301341

13311342
const contentHasher = createHash("sha256");
13321343
contentHasher.update(Buffer.from(entryPointOutputFile.text));

packages/core/src/v3/schemas/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export const Config = z.object({
212212
dependenciesToBundle: z.array(z.union([z.string(), RegexSchema])).optional(),
213213
logLevel: z.string().optional(),
214214
enableConsoleLogging: z.boolean().optional(),
215+
postInstall: z.string().optional(),
215216
});
216217

217218
export type Config = z.infer<typeof Config>;

packages/core/src/v3/types/config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,11 @@ export interface ProjectConfig {
6969
* onStart is called the first time a task is executed in a run (not before every retry)
7070
*/
7171
onStart?: (payload: unknown, params: StartFnParams) => Promise<void>;
72+
73+
/**
74+
* postInstall will run during the deploy build step, after all the dependencies have been installed.
75+
*
76+
* @example "prisma generate"
77+
*/
78+
postInstall?: string;
7279
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
datasource db {
2+
provider = "postgresql"
3+
url = env("DATABASE_URL")
4+
directUrl = env("DIRECT_URL")
5+
}
6+
7+
generator client {
8+
provider = "prisma-client-js"
9+
}
10+
11+
model User {
12+
id String @id @default(cuid())
13+
email String @unique
14+
}

references/v3-catalog/trigger.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const config: TriggerConfig = {
1616
randomize: true,
1717
},
1818
},
19-
additionalPackages: ["[email protected]", "[email protected]"],
20-
additionalFiles: ["./wrangler/wrangler.toml"],
19+
20+
additionalFiles: ["./wrangler/wrangler.toml", "./prisma/schema.prisma"],
2121
dependenciesToBundle: [/@sindresorhus/, "escape-string-regexp"],
2222
instrumentations: [new OpenAIInstrumentation()],
2323
logLevel: "log",
@@ -34,4 +34,5 @@ export const config: TriggerConfig = {
3434

3535
throw error;
3636
},
37+
postInstall: "npm exec --package prisma -- prisma generate",
3738
};

0 commit comments

Comments
 (0)