fix: Web Dockerfile — use node-linker=hoisted for flat node_modules
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 11s
CI / E2E Tests (push) Has been skipped
Deploy / Build API Image (push) Failing after 16s
Deploy / Build Web Image (push) Failing after 10s
Deploy / Build AI Services Image (push) Failing after 9s
E2E Tests / Playwright E2E (push) Failing after 12s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped

pnpm default mode creates symlinks in node_modules that break when
copied between Docker stages. Using node-linker=hoisted makes pnpm
create flat node_modules (like npm), so Next.js standalone output
contains real files instead of broken symlinks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-14 13:35:15 +07:00
parent ffdedc9841
commit 09fdc5ccbe

View File

@@ -4,15 +4,19 @@ RUN corepack enable && corepack prepare pnpm@10.27.0 --activate
WORKDIR /app
# ---- Dependencies ----
# Use node-linker=hoisted so pnpm creates flat node_modules (no symlinks).
# This ensures standalone output has real files, not broken pnpm symlinks.
FROM base AS deps
RUN echo "node-linker=hoisted" > .npmrc
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json turbo.json ./
COPY apps/web/package.json apps/web/
RUN pnpm install --frozen-lockfile --filter @goodgo/web...
# ---- Build ----
FROM base AS build
COPY --from=deps /app/.npmrc ./
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules 2>/dev/null || true
COPY tsconfig.base.json ./
COPY apps/web/ apps/web/
RUN cd apps/web && npx next build
@@ -27,19 +31,11 @@ ENV NEXT_TELEMETRY_DISABLED=1
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
# Install production deps fresh (pnpm standalone output has broken symlinks)
COPY --from=deps /app/pnpm-lock.yaml /app/pnpm-workspace.yaml /app/package.json /app/turbo.json ./
COPY --from=deps /app/apps/web/package.json ./apps/web/
RUN corepack enable && corepack prepare pnpm@10.27.0 --activate \
&& printf '#!/bin/sh\nexit 0' > /usr/local/bin/husky && chmod +x /usr/local/bin/husky \
&& pnpm install --frozen-lockfile --filter @goodgo/web... --prod
# Copy standalone server.js (the entrypoint Next.js generates)
# With hoisted node_modules, standalone output has real files (no symlinks)
COPY --from=build --chown=node:node /app/apps/web/.next/standalone/node_modules ./node_modules
COPY --from=build --chown=node:node /app/apps/web/.next/standalone/apps/web/server.js ./server.js
# Copy .next build output
COPY --from=build --chown=node:node /app/apps/web/.next/standalone/apps/web/.next ./.next
COPY --from=build --chown=node:node /app/apps/web/.next/static ./.next/static
# Copy public assets if any exist (may be empty)
COPY --from=build --chown=node:node /app/apps/web/public ./public
EXPOSE 3000