# Backend Dockerfile for Paper Dynasty Game Engine # Multi-stage build for optimized production image FROM python:3.11-slim as base # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 # Install system dependencies RUN apt-get update && apt-get install -y \ curl \ postgresql-client \ && rm -rf /var/lib/apt/lists/* # Create app directory WORKDIR /app # Development stage FROM base as development # Copy requirements COPY requirements.txt requirements-dev.txt ./ # Install Python dependencies RUN pip install -r requirements-dev.txt # Copy application code COPY . . # Expose port EXPOSE 8000 # Run with uvicorn reload for development CMD ["python", "-m", "uvicorn", "app.main:socket_app", "--host", "0.0.0.0", "--port", "8000", "--reload"] # Production stage FROM base as production # Copy requirements (production only) COPY requirements.txt ./ # Install Python dependencies RUN pip install -r requirements.txt # Create non-root user RUN useradd -m -u 1000 appuser && \ chown -R appuser:appuser /app # Copy application code COPY --chown=appuser:appuser . . # Switch to non-root user USER appuser # Expose port EXPOSE 8000 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8000/api/health || exit 1 # Run with production server CMD ["python", "-m", "uvicorn", "app.main:socket_app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]