# ============================================ # AudioForge Frontend - Production Dockerfile # ============================================ # Multi-stage build with optimized caching # Production-ready Next.js deployment FROM node:20-alpine AS base # Install security updates RUN apk upgrade --no-cache && \ apk add --no-cache libc6-compat curl # ============================================ # Dependencies Stage # ============================================ FROM base AS deps WORKDIR /app # Enable pnpm RUN corepack enable && corepack prepare pnpm@9.1.0 --activate # Copy dependency files COPY package.json pnpm-lock.yaml* ./ # Install dependencies (allow lockfile update for flexibility) RUN pnpm install --no-frozen-lockfile --prod=false # ============================================ # Builder Stage # ============================================ FROM base AS builder WORKDIR /app # Copy dependency files first for better caching COPY package.json package-lock.json* ./ # Install ALL dependencies RUN npm install # Copy source code COPY . . # Remove test files and vitest config to avoid build conflicts RUN rm -rf src/**/*.test.ts src/**/*.test.tsx src/test vitest.config.ts # Set build environment variables ENV NEXT_TELEMETRY_DISABLED=1 \ NODE_ENV=production # Build application RUN npm run build # ============================================ # Production Runner Stage # ============================================ FROM base AS runner WORKDIR /app # Set production environment ENV NODE_ENV=production \ NEXT_TELEMETRY_DISABLED=1 \ PORT=3000 \ HOSTNAME="0.0.0.0" # Create system user for security RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 nextjs # Copy built application COPY --from=builder /app/public ./public COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static # Switch to non-root user USER nextjs # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD curl -f http://localhost:3000/ || exit 1 # Expose port EXPOSE 3000 # Labels for metadata LABEL maintainer="AudioForge Team" \ version="1.0.0" \ description="AudioForge Frontend - Production Ready" \ org.opencontainers.image.source="https://github.com/audioforge/audioforge" # Start application CMD ["node", "server.js"]