# ============================================================================= # OrbiQuant IA - Backend API # Multi-stage Dockerfile for production deployment # ============================================================================= # ----------------------------------------------------------------------------- # Stage 1: Dependencies # ----------------------------------------------------------------------------- FROM node:20-alpine AS deps WORKDIR /app # Install dependencies for native modules RUN apk add --no-cache libc6-compat python3 make g++ # Copy package files COPY package*.json ./ # Install all dependencies (including dev for build) RUN npm ci # ----------------------------------------------------------------------------- # Stage 2: Builder # ----------------------------------------------------------------------------- FROM node:20-alpine AS builder WORKDIR /app # Copy dependencies from deps stage COPY --from=deps /app/node_modules ./node_modules COPY . . # Build TypeScript RUN npm run build # Remove dev dependencies RUN npm prune --production # ----------------------------------------------------------------------------- # Stage 3: Production # ----------------------------------------------------------------------------- FROM node:20-alpine AS runner WORKDIR /app # Create non-root user for security RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 orbiquant # Set production environment ENV NODE_ENV=production ENV PORT=3000 # Copy necessary files COPY --from=builder /app/dist ./dist COPY --from=builder /app/node_modules ./node_modules COPY --from=builder /app/package.json ./package.json # Change ownership RUN chown -R orbiquant:nodejs /app # Switch to non-root user USER orbiquant # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1 # Start application CMD ["node", "dist/index.js"]