# ============================================================================= # MiChangarrito - Backend Dockerfile # ============================================================================= # Multi-stage build for NestJS application # Puerto: 3141 # ============================================================================= # Build stage FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies RUN npm ci # Copy source code COPY . . # Build application RUN npm run build # Production stage FROM node:20-alpine AS production # Labels LABEL maintainer="ISEM" LABEL description="MiChangarrito Backend API" LABEL version="1.0.0" WORKDIR /app # Copy package files COPY package*.json ./ # Install only production dependencies RUN npm ci --only=production && npm cache clean --force # Copy built application COPY --from=builder /app/dist ./dist # Create non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nestjs -u 1001 -G nodejs # Set ownership RUN chown -R nestjs:nodejs /app USER nestjs # Environment ENV NODE_ENV=production ENV PORT=3141 # Expose port EXPOSE 3141 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3141/api/v1/health || exit 1 # Start application CMD ["node", "dist/main"] # Development stage FROM node:20-alpine AS development WORKDIR /app # Copy package files COPY package*.json ./ # Install all dependencies RUN npm ci # Copy source code COPY . . # Environment ENV NODE_ENV=development ENV PORT=3141 # Expose port EXPOSE 3141 # Start in development mode CMD ["npm", "run", "start:dev"]