Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/code-layer-exclude-copy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fixes an issue introduced in 4.5.11 that made deploy image builds of projects with large dependency trees noticeably slower.
11 changes: 6 additions & 5 deletions packages/cli-v3/src/deploy/buildImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ describe("generateContainerfile", () => {

const user = runtime === "bun" ? "bun:bun" : "node:node";

expect(containerfile).toContain("FROM build AS code");
expect(containerfile).toContain("FROM scratch AS code");
expect(containerfile).toContain("COPY --from=build --exclude=node_modules /app /app");
expect(containerfile).toContain(
`COPY --from=build --chown=${user} /app/node_modules ./node_modules`
);
Expand All @@ -180,15 +181,15 @@ describe("generateContainerfile", () => {
const postInstall = containerfile.indexOf("RUN echo post-install");
// guard after post-install so a command that prunes node_modules can't break the COPY
const mkdirGuard = containerfile.indexOf("RUN mkdir -p node_modules");
const codeStage = containerfile.indexOf("FROM build AS code");
const rmNodeModules = containerfile.indexOf(
"RUN chmod -R u+rwX node_modules && rm -rf node_modules"
const codeStage = containerfile.indexOf("FROM scratch AS code");
const excludeCopy = containerfile.indexOf(
"COPY --from=build --exclude=node_modules /app /app"
);

expect(postInstall).toBeGreaterThan(-1);
expect(mkdirGuard).toBeGreaterThan(postInstall);
expect(codeStage).toBeGreaterThan(mkdirGuard);
expect(rmNodeModules).toBeGreaterThan(codeStage);
expect(excludeCopy).toBeGreaterThan(codeStage);
}
);
});
10 changes: 4 additions & 6 deletions packages/cli-v3/src/deploy/buildImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,9 @@ ${postInstallCommands}
# node_modules may not exist when there are no dependencies to install
RUN mkdir -p node_modules

FROM build AS code
FROM scratch AS code

# u+rwX first: non-root rm fails on read-only or non-traversable directories
RUN chmod -R u+rwX node_modules && rm -rf node_modules
COPY --from=build --exclude=node_modules /app /app

FROM build AS indexer

Expand Down Expand Up @@ -945,10 +944,9 @@ COPY --chown=node:node . .
# node_modules may not exist when there are no dependencies to install
RUN mkdir -p node_modules

FROM build AS code
FROM scratch AS code

# u+rwX first: non-root rm fails on read-only or non-traversable directories
RUN chmod -R u+rwX node_modules && rm -rf node_modules
COPY --from=build --exclude=node_modules /app /app

FROM build AS indexer

Expand Down