# Multi-stage build for Next.js frontend FROM node:18-alpine AS base # Install dependencies for image processing RUN apk add --no-cache libc6-compat WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies RUN npm ci --only=production && npm cache clean --force # Development stage FROM base AS development # Install dev dependencies RUN npm install --only=development # Copy source code COPY . . # Expose port EXPOSE 3000 # Start development server CMD ["npm", "run", "dev"] # Production build stage FROM base AS builder # Install dev dependencies for build RUN npm install --only=development # Copy source code COPY . . # Set environment variables for build ENV NEXT_TELEMETRY_DISABLED 1 ENV NODE_ENV production # Build the application RUN npm run build # Production stage FROM node:18-alpine AS production # Install curl for health checks RUN apk add --no-cache curl WORKDIR /app # Copy built application COPY --from=builder /app/public ./public COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static # Switch to non-root user USER node EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:3000/api/health || exit 1 CMD ["node", "server.js"]