fix: Web Dockerfile — add flatten stage for pnpm standalone structure
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 9s
CI / E2E Tests (push) Has been skipped
Deploy / Build API Image (push) Failing after 14s
Deploy / Build Web Image (push) Failing after 11s
Deploy / Build AI Services Image (push) Failing after 10s
E2E Tests / Playwright E2E (push) Failing after 15s
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 standalone output has nested .pnpm structure with symlinks.
Add intermediate flatten stage: copy full standalone dir, then
reorganize node_modules + apps/web/* into flat /app layout.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ho Ngoc Hai
2026-04-14 00:51:45 +07:00
parent 3de953223a
commit 25c05c408a

View File

@@ -17,6 +17,18 @@ COPY tsconfig.base.json ./
COPY apps/web/ apps/web/
RUN cd apps/web && npx next build
# ---- Flatten standalone ----
# Next.js standalone with outputFileTracingRoot at repo root creates:
# .next/standalone/ → node_modules/.pnpm/... + apps/web/server.js
# We flatten it so /app has server.js + node_modules/ + .next/
FROM node:22-slim AS flatten
WORKDIR /app
COPY --from=build /app/apps/web/.next/standalone/ /standalone/
RUN cp -r /standalone/node_modules /app/node_modules && \
cp -r /standalone/apps/web/* /app/ 2>/dev/null || true && \
cp -r /standalone/apps/web/.next /app/.next 2>/dev/null || true && \
rm -rf /standalone
# ---- Production ----
FROM node:22-slim AS production
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init && rm -rf /var/lib/apt/lists/*
@@ -27,15 +39,9 @@ ENV NEXT_TELEMETRY_DISABLED=1
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
# Copy Next.js standalone output
# With outputFileTracingRoot=repo_root, standalone structure is:
# .next/standalone/node_modules/ → real deps (not symlinks)
# .next/standalone/apps/web/ → server.js, .next/, package.json
RUN mkdir -p ./public ./.next/static
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 --from=build --chown=node:node /app/apps/web/.next/standalone/apps/web/package.json ./package.json
COPY --from=build --chown=node:node /app/apps/web/.next/standalone/apps/web/.next ./.next
# Copy flattened standalone
RUN mkdir -p ./public
COPY --from=flatten --chown=node:node /app ./
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