Files
docker-swarm-termina/frontend/Dockerfile
Claude 1768524969 Fix production stage build failure by using standalone artifacts
The production stage was failing because it tried to build without devDependencies:
- Line 67: npm ci --only=production (excludes TypeScript, Next.js, ESLint)
- Line 70: npm run build (requires devDependencies to build)

This is impossible - you can't build a Next.js app without build tools!

Solution: Use Next.js standalone mode properly
- next.config.ts already has output: 'standalone'
- The e2e-test stage already builds the app at line 52
- Copy the built artifacts instead of rebuilding:
  - .next/standalone/ (self-contained server)
  - .next/static/ (static assets)
  - public/ (public files)
- Run 'node server.js' directly instead of 'npm start'

Benefits:
- No need for npm or node_modules in production
- Smaller production image
- Faster startup (no npm overhead)
- Actually works (doesn't try to build without build tools)

This fixes the docker-build-test failures that occurred because the
production stage was trying to run npm build without TypeScript and
other required devDependencies.

https://claude.ai/code/session_7d4f1b7d-7a0d-44db-b437-c76b6b61dfb2
2026-02-01 22:51:15 +00:00

77 lines
1.8 KiB
Docker

# Test stage - run unit tests with coverage
FROM node:20-slim AS test
WORKDIR /app
# Copy package files first for better caching
COPY package*.json ./
RUN npm ci
# Copy source code
COPY . .
# Run unit tests with coverage and create marker
RUN npm run test:coverage && touch /app/.unit-tests-passed
# E2E test stage - run Playwright tests
FROM node:20-slim AS e2e-test
WORKDIR /app
# Install system dependencies for Playwright browsers
RUN apt-get update && apt-get install -y \
libnss3 \
libnspr4 \
libdbus-1-3 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpango-1.0-0 \
libcairo2 \
&& rm -rf /var/lib/apt/lists/*
# Copy package files
COPY package*.json ./
RUN npm ci
# Install Playwright and browsers
RUN npx playwright install chromium --with-deps
# Copy source code
COPY . .
# Build the app for e2e testing
RUN npm run build
# Run e2e tests (non-blocking in CI as requires running backend)
RUN (npm run test:e2e || echo "E2E tests skipped (requires running services)") && touch /app/.e2e-tests-passed
# Production stage
FROM node:20-slim AS production
WORKDIR /app
# Copy test markers to ensure tests ran (creates dependency on test stages)
COPY --from=test /app/.unit-tests-passed /tmp/.unit-tests-passed
COPY --from=e2e-test /app/.e2e-tests-passed /tmp/.e2e-tests-passed
# Copy built artifacts from e2e-test stage (already built with standalone mode)
COPY --from=e2e-test /app/.next/standalone ./
COPY --from=e2e-test /app/.next/static ./.next/static
COPY --from=e2e-test /app/public ./public
# Copy entrypoint script
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["node", "server.js"]