Skip to content

Commit 0b596a3

Browse files
committed
fix(docker,ci): fix two CI/CD failures
1. pnpm-lock.yaml outdated (ERR_PNPM_OUTDATED_LOCKFILE) apps/template/backend was added to the workspace but pnpm install was never run — lockfile had empty specifiers for that package. Fixed by running pnpm install at root. 2. Docker build: better-sqlite3 node-gyp fails — no Python in node:22-slim - Builder stage: add python3 make g++ via apt before pnpm install - Runtime stage: replace 'npm install --omit=dev --ignore-scripts' (which breaks native modules) with 'pnpm deploy --prod' in builder then copy the flat deploy/node_modules to runtime. This carries the compiled better-sqlite3.node binary without needing Python at runtime.
1 parent df96cef commit 0b596a3

File tree

3 files changed

+153
-11
lines changed

3 files changed

+153
-11
lines changed

apps/cas/backend/Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ FROM node:22-slim AS builder
1414

1515
WORKDIR /app
1616

17+
# Install build tools required by native modules (better-sqlite3 → node-gyp)
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
19+
python3 make g++ \
20+
&& rm -rf /var/lib/apt/lists/*
21+
1722
# Install pnpm
1823
RUN corepack enable && corepack prepare pnpm@10.11.0 --activate
1924

@@ -28,6 +33,9 @@ COPY apps/cas/backend/ ./apps/cas/backend/
2833

2934
RUN pnpm --filter @cfxdevkit/cas-backend build
3035

36+
# Create a production-only flat bundle (includes compiled native bindings)
37+
RUN pnpm deploy --filter @cfxdevkit/cas-backend --prod /app/deploy
38+
3139
# ── Stage 2: runtime ─────────────────────────────────────────────────────────
3240
FROM node:22-slim AS runtime
3341

@@ -36,11 +44,10 @@ LABEL org.opencontainers.image.title="cas-backend" \
3644

3745
WORKDIR /app
3846

39-
# Only production deps
40-
COPY --from=builder /app/apps/cas/backend/package.json ./
41-
RUN npm install --omit=dev --ignore-scripts
42-
47+
# Copy production node_modules from deploy bundle (includes compiled better-sqlite3)
48+
COPY --from=builder /app/deploy/node_modules ./node_modules
4349
COPY --from=builder /app/apps/cas/backend/dist ./dist
50+
COPY --from=builder /app/apps/cas/backend/package.json ./
4451

4552
# Non-root user
4653
RUN addgroup --system cas && adduser --system --ingroup cas cas

apps/template/backend/Dockerfile

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ FROM node:22-slim AS builder
1414

1515
WORKDIR /app
1616

17+
# Install build tools required by native modules (better-sqlite3 → node-gyp)
18+
RUN apt-get update && apt-get install -y --no-install-recommends \
19+
python3 make g++ \
20+
&& rm -rf /var/lib/apt/lists/*
21+
1722
# Install pnpm
1823
RUN corepack enable && corepack prepare pnpm@10.11.0 --activate
1924

@@ -28,6 +33,9 @@ COPY apps/template/backend/ ./apps/template/backend/
2833

2934
RUN pnpm --filter @cfxdevkit/template-backend build
3035

36+
# Create a production-only flat bundle (includes compiled native bindings)
37+
RUN pnpm deploy --filter @cfxdevkit/template-backend --prod /app/deploy
38+
3139
# ── Stage 2: runtime ─────────────────────────────────────────────────────────
3240
FROM node:22-slim AS runtime
3341

@@ -36,11 +44,10 @@ LABEL org.opencontainers.image.title="template-backend" \
3644

3745
WORKDIR /app
3846

39-
# Only production deps
40-
COPY --from=builder /app/apps/template/backend/package.json ./
41-
RUN npm install --omit=dev --ignore-scripts
42-
47+
# Copy production node_modules from deploy bundle (includes compiled better-sqlite3)
48+
COPY --from=builder /app/deploy/node_modules ./node_modules
4349
COPY --from=builder /app/apps/template/backend/dist ./dist
50+
COPY --from=builder /app/apps/template/backend/package.json ./
4451

4552
# Non-root user
4653
RUN addgroup --system template && adduser --system --ingroup template template

pnpm-lock.yaml

Lines changed: 131 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)