# Use Python 3.11 slim image for better performance and smaller size FROM python:3.11-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV DEBIAN_FRONTEND=noninteractive # Set work directory WORKDIR /app # Install system dependencies RUN apt-get update \ && apt-get install -y --no-install-recommends \ postgresql-client \ gcc \ python3-dev \ libpq-dev \ curl \ && rm -rf /var/lib/apt/lists/* # Copy requirements first to leverage Docker cache COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy project files COPY . . # Create logs directory RUN mkdir -p logs # Create non-root user for security RUN adduser --disabled-password --gecos '' appuser && chown -R appuser:appuser /app USER appuser # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8000/health/ || exit 1 # Expose port EXPOSE 8000 # Run gunicorn CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "netcop_hub.wsgi:application"]