FROM node:20-alpine AS builder WORKDIR /app # Install dependencies COPY package*.json ./ RUN npm ci --only=production && npm cache clean --force # Copy source COPY . . # Build TypeScript RUN npm run build # Production stage FROM node:20-alpine WORKDIR /app # Install only production dependencies COPY package*.json ./ RUN npm ci --only=production && npm cache clean --force # Copy built files COPY --from=builder /app/dist ./dist COPY --from=builder /app/src/generated ./src/generated # Create data directory with proper permissions RUN mkdir -p /app/data && chown -R node:node /app/data # Switch to non-root user USER node # Expose port EXPOSE 3001 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD node -e "require('http').get('http://localhost:3001/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})" # Start production server CMD ["node", "dist/index.js"]