# ============================================================================== # GAMILIT BACKEND - NestJS Dockerfile # ============================================================================== # Multi-stage build for production-ready NestJS application # ============================================================================== # Stage 1: Dependencies FROM node:20-alpine AS deps WORKDIR /app # Install dependencies only when needed COPY package*.json ./ RUN npm ci --only=production && npm cache clean --force # Stage 2: Builder FROM node:20-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build # Stage 3: Production FROM node:20-alpine AS runner WORKDIR /app ENV NODE_ENV=production # Create non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nestjs # Copy built application COPY --from=builder /app/dist ./dist COPY --from=deps /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json USER nestjs EXPOSE 3000 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1 CMD ["node", "dist/main.js"]