Spaces:
Sleeping
Sleeping
| # Multi-stage build — keeps final image small and dependency-free from build tools | |
| # ── Stage 1: Build ──────────────────────────────────────────────────────────── | |
| FROM python:3.11-slim AS builder | |
| WORKDIR /app | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --user -r requirements.txt | |
| # ── Stage 2: Runtime ────────────────────────────────────────────────────────── | |
| FROM python:3.11-slim | |
| WORKDIR /app | |
| # Non-root user for security | |
| RUN useradd -m -u 1001 appuser | |
| # Copy installed packages from builder | |
| COPY --from=builder /root/.local /home/appuser/.local | |
| # Copy application source | |
| COPY --chown=appuser:appuser . . | |
| # Create writable dirs the app needs | |
| RUN mkdir -p models data/raw data/processed reports metrics \ | |
| && chown -R appuser:appuser models data reports metrics | |
| USER appuser | |
| ENV PATH=/home/appuser/.local/bin:$PATH \ | |
| PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 | |
| EXPOSE 8000 | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \ | |
| CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" | |
| CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"] | |