FROM node:20-alpine AS frontend-builder # Build frontend WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm ci COPY frontend/ ./ # Build for production with relative API paths RUN npm run build # Main container with Python and built frontend FROM python:3.11-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ ffmpeg \ && rm -rf /var/lib/apt/lists/* # Copy and install Python dependencies COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy backend application COPY . ./ # Copy built frontend from builder stage COPY --from=frontend-builder /app/frontend/dist ./frontend/dist # Create necessary directories RUN mkdir -p uploads # Set environment variables ENV PYTHONPATH=/app ENV FLASK_APP=app.py ENV FLASK_ENV=production # Expose single port EXPOSE 12015 # Health check HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=40s \ CMD curl -f http://localhost:12015/api/health || exit 1 # Run with Gunicorn for production CMD ["gunicorn", "--bind", "0.0.0.0:12015", "--worker-class", "gthread", "--workers", "4", "--threads", "8", "--timeout", "120", "--keep-alive", "10", "--max-requests", "2000", "--max-requests-jitter", "200", "--forwarded-allow-ips", "*", "--access-logfile", "-", "app:app"]