Skip to content

Commit c4d5ca8

Browse files
committed
fix(docker): drop pnpm deploy, copy node_modules directly from builder
pnpm deploy --legacy does a fresh install that skips build scripts even after find+cp of the .node file into the deploy dir failed to produce the binary in the correct location. Fix: skip pnpm deploy entirely. After pnpm rebuild better-sqlite3 the compiled better_sqlite3.node is in /app/node_modules at the expected .pnpm virtual-store path. Copy that entire node_modules into the runtime stage — the binary is guaranteed to be present.
1 parent b8e0cf2 commit c4d5ca8

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

apps/cas/backend/Dockerfile

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,6 @@ RUN pnpm rebuild better-sqlite3
4040
COPY --from=pruner /app/out/full/ .
4141
RUN pnpm --filter @cfxdevkit/cas-backend build
4242

43-
# Create prod-only bundle — workspace deps resolve because prune provided them
44-
RUN pnpm deploy --filter @cfxdevkit/cas-backend --prod --legacy /app/deploy
45-
46-
# Copy the compiled better_sqlite3.node binary from builder into the deploy dir.
47-
# pnpm deploy does a fresh install without running build scripts, so the binary
48-
# would be missing. We copy it from the already-compiled location instead.
49-
RUN find /app/node_modules -name "better_sqlite3.node" | while read src; do \
50-
rel="${src#/app/node_modules/}"; \
51-
dst="/app/deploy/node_modules/$rel"; \
52-
mkdir -p "$(dirname $dst)"; \
53-
cp "$src" "$dst"; \
54-
done
55-
5643
# ── Stage 2: runtime ─────────────────────────────────────────────────────────
5744
FROM node:22-slim AS runtime
5845

@@ -61,7 +48,11 @@ LABEL org.opencontainers.image.title="cas-backend" \
6148

6249
WORKDIR /app
6350

64-
COPY --from=builder /app/deploy/node_modules ./node_modules
51+
# Copy node_modules directly from builder — the compiled better_sqlite3.node
52+
# binary is already present there from the pnpm rebuild step above.
53+
# (pnpm deploy performs a fresh install that skips build scripts, so the
54+
# binary is absent in a deploy dir — skip deploy entirely.)
55+
COPY --from=builder /app/node_modules ./node_modules
6556
COPY --from=builder /app/apps/cas/backend/dist ./dist
6657
COPY --from=builder /app/apps/cas/backend/package.json ./
6758

apps/template/backend/Dockerfile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ RUN pnpm rebuild better-sqlite3
2929
COPY apps/template/backend/ ./apps/template/backend/
3030
RUN pnpm --filter @cfxdevkit/template-backend build
3131

32-
# Create prod-only bundle
33-
RUN pnpm deploy --filter @cfxdevkit/template-backend --prod --legacy /app/deploy
34-
35-
# Copy the compiled better_sqlite3.node binary into the deploy dir.
36-
RUN find /app/node_modules -name "better_sqlite3.node" | while read src; do \
37-
rel="${src#/app/node_modules/}"; \
38-
dst="/app/deploy/node_modules/$rel"; \
39-
mkdir -p "$(dirname $dst)"; \
40-
cp "$src" "$dst"; \
41-
done
42-
4332
# ── Stage 2: runtime ─────────────────────────────────────────────────────────
4433
FROM node:22-slim AS runtime
4534

@@ -48,7 +37,11 @@ LABEL org.opencontainers.image.title="template-backend" \
4837

4938
WORKDIR /app
5039

51-
COPY --from=builder /app/deploy/node_modules ./node_modules
40+
# Copy node_modules directly from builder — the compiled better_sqlite3.node
41+
# binary is already present there from the pnpm rebuild step above.
42+
# (pnpm deploy performs a fresh install that skips build scripts, so the
43+
# binary is absent in a deploy dir — skip deploy entirely.)
44+
COPY --from=builder /app/node_modules ./node_modules
5245
COPY --from=builder /app/apps/template/backend/dist ./dist
5346
COPY --from=builder /app/apps/template/backend/package.json ./
5447

0 commit comments

Comments
 (0)