# ============================================================================== # BETTING-ANALYTICS ML ENGINE - Python FastAPI Dockerfile # ============================================================================== # Multi-stage build for ML service with optional GPU support # ============================================================================== # Stage 1: Builder FROM python:3.11-slim AS builder WORKDIR /app # Install build dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Install Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # Stage 2: Production FROM python:3.11-slim AS runner WORKDIR /app ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PATH="/home/appuser/.local/bin:$PATH" # Create non-root user RUN addgroup --system --gid 1001 appgroup RUN adduser --system --uid 1001 --gid 1001 appuser # Copy Python packages from builder COPY --from=builder /root/.local /home/appuser/.local # Copy application code COPY --chown=appuser:appgroup . . USER appuser EXPOSE 3093 HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:3093/health')" || exit 1 CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "3093"]