feat: add production Docker setup with multi-stage builds

- Add production Dockerfiles for frontend and backend
  * Frontend: multi-stage build with nginx serving static files
  * Backend: multi-stage build with Prisma generation
- Create production nginx configuration (nginx/conf.d.prod/)
  * Routes to frontend-prod:80 and backend-prod:3000
  * Supports WebSocket connections for Socket.IO
- Update docker-compose.yml to use production config
  * Add env_file support for backend-prod
  * Mount production nginx config directory
- Add .env.production.example template for deployment
This commit is contained in:
Radosław Gierwiało
2025-11-15 17:21:25 +01:00
parent b50c20fae7
commit a400068053
5 changed files with 171 additions and 57 deletions

57
backend/Dockerfile.prod Normal file
View File

@@ -0,0 +1,57 @@
# Multi-stage build for production
# Stage 1: Build
FROM node:20-alpine AS builder
# Install OpenSSL for Prisma
RUN apk add --no-cache openssl
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies for Prisma generation)
RUN npm ci
# Copy application files
COPY . .
# Generate Prisma Client
RUN npx prisma generate
# Stage 2: Production
FROM node:20-alpine
# Install OpenSSL for Prisma
RUN apk add --no-cache openssl
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm ci --only=production
# Copy application files and generated Prisma Client from builder
COPY --from=builder /app/src ./src
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder /app/node_modules/@prisma ./node_modules/@prisma
# Copy entrypoint script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Set environment to production
ENV NODE_ENV=production
# Expose port
EXPOSE 3000
# Set entrypoint
ENTRYPOINT ["docker-entrypoint.sh"]
# Start the application
CMD ["node", "src/server.js"]