Skip to content
Merged
Changes from 4 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
33 changes: 25 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ RUN --mount=type=cache,id=npm-build-stage-v4-${NPM_CACHE_KEY},target=/root/.npm,
npm ci --legacy-peer-deps --no-audit --no-fund && \
(npm cache verify 2>/dev/null || true)

# Checkpoint right after npm ci, before any per-workspace build runs: every
# workspace's node_modules is fully installed and final here. deps-production-*
# copies node_modules from this stage instead of the final `build` stage below
# — `COPY --from=<stage>` always waits for that stage's LAST instruction, and
# `RUN npm run build --workspace=packages/backend` (further down) intermittently
# corrupted BuildKit's cache-key resolution for a later COPY of
# packages/backend/node_modules from that same stage ("failed to calculate
# checksum of ref ...: not found" immediately after that RUN completed —
# reproduced consistently across buildx versions, with/without the GHA cache,
# concurrent and alone; never root-caused beyond decoupling the two). None of
# the per-workspace build scripts write into node_modules, so this is a
# behavior-neutral extraction point, not a functional change.
FROM build AS installed-deps
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
COPY packages/shared ./packages/shared
COPY packages/bot ./packages/bot
COPY packages/backend ./packages/backend
Expand All @@ -89,12 +103,15 @@ RUN npm run build:shared
RUN npm run build --workspace=packages/bot
RUN npm run build --workspace=packages/backend

# Frontend build — inherits the build stage's deps + toolchain, so we get
# Frontend build — inherits installed-deps' deps + toolchain, so we get
# build-base + python3-dev + opus-dev "for free." Previously the standalone
# Dockerfile.frontend re-ran `npm ci` for ~all workspace deps (including
# @discordjs/opus) but lacked the C toolchain, which broke node:26-alpine
# in PR #846. Sharing the build stage eliminates that class of failure.
FROM build AS build-frontend
# Must branch from installed-deps, not build: installed-deps is where
# build:shared runs, and frontend imports @lucky/shared/constants, which
# only resolves once shared's dist output exists.
FROM installed-deps AS build-frontend
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
COPY packages/frontend ./packages/frontend
# Frontend's /changelog page imports the repo-root CHANGELOG.md via
# `import md from '../../../../CHANGELOG.md?raw'` (vite raw loader). The
Expand Down Expand Up @@ -136,17 +153,17 @@ COPY packages/bot/package*.json ./packages/bot/
COPY packages/backend/package*.json ./packages/backend/
COPY packages/frontend/package*.json ./packages/frontend/

# Reuse already-compiled node_modules from build stage (avoids double @discordjs/opus
# compilation).
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/packages/shared/node_modules ./packages/shared/node_modules
# Reuse already-compiled node_modules from the pre-build checkpoint (avoids
# double @discordjs/opus compilation).
COPY --from=installed-deps /app/node_modules ./node_modules
COPY --from=installed-deps /app/packages/shared/node_modules ./packages/shared/node_modules

FROM deps-production-base AS deps-production-bot
COPY --from=build /app/packages/bot/node_modules ./packages/bot/node_modules
COPY --from=installed-deps /app/packages/bot/node_modules ./packages/bot/node_modules
RUN npm prune --omit=dev --legacy-peer-deps

FROM deps-production-base AS deps-production-backend
COPY --from=build /app/packages/backend/node_modules ./packages/backend/node_modules
COPY --from=installed-deps /app/packages/backend/node_modules ./packages/backend/node_modules
RUN npm prune --omit=dev --legacy-peer-deps

# Production stage — bot (full runtime with ffmpeg/opus/yt-dlp)
Expand Down
Loading