# Build stage FROM node:18-alpine AS builder WORKDIR /app # Install build dependencies RUN apk add --no-cache python3 make g++ # Copy package files COPY package*.json ./ # Install all dependencies (including dev) RUN npm ci # Copy source code COPY . . # Build the application RUN npm run build # Prune dev dependencies RUN npm prune --production # Production stage FROM node:18-alpine AS production # Install ffmpeg for video processing RUN apk add --no-cache ffmpeg WORKDIR /app # Create non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nestjs -u 1001 # Copy built application from builder COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules COPY --from=builder --chown=nestjs:nodejs /app/package.json ./package.json # Set environment variables ENV NODE_ENV=production ENV PORT=3142 # Switch to non-root user USER nestjs # Expose port EXPOSE 3142 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3142/api/v1/health || exit 1 # Start the application CMD ["node", "dist/main.js"]