Spaces:
Running
Running
| # --- Base image --- | |
| FROM python:3.11-slim | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_NO_CACHE_DIR=on | |
| # OS deps (git useful for HF repos; curl for HEALTHCHECK) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| git curl && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Non-root user | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| WORKDIR /app | |
| # Python deps | |
| COPY --chown=user ./requirements.txt requirements.txt | |
| RUN pip install --upgrade pip && pip install -r requirements.txt | |
| # App source | |
| COPY --chown=user . /app | |
| EXPOSE 7860 | |
| # Healthcheck pings your FastAPI health endpoint | |
| HEALTHCHECK --interval=30s --timeout=3s --start-period=20s --retries=3 \ | |
| CMD curl -fsS http://localhost:7860/api/health || exit 1 | |
| # Production server (Gunicorn + Uvicorn worker) | |
| #CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |
| CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-w", "2", "-b", "0.0.0.0:7860", "server:app"] | |