# Multi-stage build for Corrosion NestJS API # Stage 1: Build FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies RUN npm ci # Copy source COPY . . # Build TypeScript RUN npm run build # Stage 2: Production FROM node:20-alpine WORKDIR /app # Copy built output and production dependencies COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./ # Non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nestjs -u 1001 && \ chown -R nestjs:nodejs /app USER nestjs EXPOSE 3000 CMD ["node", "dist/main.js"]