Add a postInstall option to allow running scripts after dependencies have been installed in deployed images

This commit is contained in:
Eric Allam
2024-05-01 14:16:52 +01:00
parent 9e5382951b
commit e337b21650
7 changed files with 46 additions and 4 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---
Add a postInstall option to allow running scripts after dependencies have been installed in deployed images
+2
View File
@@ -19,6 +19,8 @@ COPY --chown=node:node . .
USER node
RUN npm ci --no-fund --no-audit && npm cache clean --force
__POST_INSTALL__
# Development or production stage builds upon the base stage
FROM base AS final
+13 -2
View File
@@ -1325,8 +1325,19 @@ async function compileProject(
// Write the Containerfile to /tmp/dir/Containerfile
const containerFilePath = join(cliRootPath(), "Containerfile.prod");
// Copy the Containerfile to /tmp/dir/Containerfile
await copyFile(containerFilePath, join(tempDir, "Containerfile"));
let containerFileContents = readFileSync(containerFilePath, "utf-8");
if (config.postInstall) {
containerFileContents = containerFileContents.replace(
"__POST_INSTALL__",
`RUN ${config.postInstall}`
);
} else {
containerFileContents = containerFileContents.replace("__POST_INSTALL__", "");
}
await writeFile(join(tempDir, "Containerfile"), containerFileContents);
const contentHasher = createHash("sha256");
contentHasher.update(Buffer.from(entryPointOutputFile.text));
+1
View File
@@ -212,6 +212,7 @@ export const Config = z.object({
dependenciesToBundle: z.array(z.union([z.string(), RegexSchema])).optional(),
logLevel: z.string().optional(),
enableConsoleLogging: z.boolean().optional(),
postInstall: z.string().optional(),
});
export type Config = z.infer<typeof Config>;
+7
View File
@@ -69,4 +69,11 @@ export interface ProjectConfig {
* onStart is called the first time a task is executed in a run (not before every retry)
*/
onStart?: (payload: unknown, params: StartFnParams) => Promise<void>;
/**
* postInstall will run during the deploy build step, after all the dependencies have been installed.
*
* @example "prisma generate"
*/
postInstall?: string;
}
@@ -0,0 +1,14 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_URL")
}
generator client {
provider = "prisma-client-js"
}
model User {
id String @id @default(cuid())
email String @unique
}
+3 -2
View File
@@ -16,8 +16,8 @@ export const config: TriggerConfig = {
randomize: true,
},
},
additionalPackages: ["wrangler@3.35.0", "pg@8.11.5"],
additionalFiles: ["./wrangler/wrangler.toml"],
additionalPackages: ["wrangler@3.35.0", "pg@8.11.5", "prisma@5.11.0"],
additionalFiles: ["./wrangler/wrangler.toml", "./prisma/schema.prisma"],
dependenciesToBundle: [/@sindresorhus/, "escape-string-regexp"],
instrumentations: [new OpenAIInstrumentation()],
logLevel: "log",
@@ -34,4 +34,5 @@ export const config: TriggerConfig = {
throw error;
},
postInstall: "npm exec --package prisma -- prisma generate",
};