Files
stack/apps/web/Dockerfile
Jason Woltje 0495c48418
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
fix(docker): Copy node_modules from builder instead of reinstalling
pnpm stores the Prisma client in the content-addressable store at
node_modules/.pnpm/.../.prisma, not at apps/api/node_modules/.prisma.
The production stage was trying to copy from the wrong location.

Additionally, running `pnpm install --prod` in production failed because:
1. The husky prepare script runs but husky is a devDependency
2. The Prisma client postinstall can't run without the prisma CLI

Fixed by copying the full node_modules from the builder stage, which
already has all dependencies properly installed and the Prisma client
generated in the correct pnpm store location.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 00:42:34 -06:00

101 lines
2.8 KiB
Docker

# Base image for all stages
FROM node:20-alpine AS base
# Install pnpm globally
RUN corepack enable && corepack prepare pnpm@10.19.0 --activate
# Set working directory
WORKDIR /app
# Copy monorepo configuration files
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
COPY turbo.json ./
# ======================
# Dependencies stage
# ======================
FROM base AS deps
# Copy all package.json files for workspace resolution
COPY packages/shared/package.json ./packages/shared/
COPY packages/ui/package.json ./packages/ui/
COPY packages/config/package.json ./packages/config/
COPY apps/web/package.json ./apps/web/
# Install dependencies
RUN pnpm install --frozen-lockfile
# ======================
# Builder stage
# ======================
FROM base AS builder
# Copy dependencies
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/packages ./packages
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules
# Copy all source code
COPY packages ./packages
COPY apps/web ./apps/web
# Build arguments for Next.js
ARG NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
# Build the web app and its dependencies using TurboRepo
# This ensures @mosaic/shared and @mosaic/ui are built first
RUN pnpm turbo build --filter=@mosaic/web
# ======================
# Production stage
# ======================
FROM node:20-alpine AS production
# Install pnpm (needed for pnpm start command)
RUN corepack enable && corepack prepare pnpm@10.19.0 --activate
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create non-root user
RUN addgroup -g 1001 -S nodejs && adduser -S nextjs -u 1001
WORKDIR /app
# Copy node_modules from builder (includes all dependencies in pnpm store)
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
# Copy built packages (includes dist/ directories)
COPY --from=builder --chown=nextjs:nodejs /app/packages ./packages
# Copy built web application
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next ./apps/web/.next
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/public ./apps/web/public
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/next.config.ts ./apps/web/
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/package.json ./apps/web/
# Set working directory to web app
WORKDIR /app/apps/web
# Switch to non-root user
USER nextjs
# Expose web port
EXPOSE 3000
# Environment variables
ENV NODE_ENV=production
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the application
CMD ["pnpm", "start"]