# Multi-stage build for production optimization FROM node:18-alpine AS builder # Set working directory WORKDIR /app # Copy package files COPY package*.json ./ COPY tsconfig.json ./ # Install dependencies RUN npm ci --only=production && npm cache clean --force # Copy source code COPY src/ ./src/ # Build the application RUN npm run build # Production stage FROM node:18-alpine AS production # Create app directory WORKDIR /app # Copy package files COPY package*.json ./ # Install only production dependencies RUN npm ci --only=production && npm cache clean --force # Copy built application from builder stage COPY --from=builder /app/dist ./dist # Copy configuration files COPY config/ ./config/ # Create uploads directory RUN mkdir -p uploads logs # Create non-root user for security RUN addgroup -g 1001 -S nodejs RUN adduser -S nodeuser -u 1001 # Change ownership of the app directory RUN chown -R nodeuser:nodejs /app # Switch to non-root user USER nodeuser # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node -e "require('http').get('http://localhost:3000/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })" || exit 1 # Start the application CMD ["node", "dist/bot.js"]