Spaces:
Sleeping
Sleeping
| FROM python:3.9-slim | |
| # Prevent Python from writing pyc files & enable unbuffered logs | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 | |
| WORKDIR /app | |
| # System dependencies (minimal) | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| gcc \ | |
| g++ \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Upgrade pip first | |
| RUN pip install --upgrade pip | |
| # Copy requirements first (better caching) | |
| COPY requirements.txt . | |
| # ---- FORCE CPU-ONLY TORCH ---- | |
| RUN pip install --no-cache-dir \ | |
| torch --index-url https://download.pytorch.org/whl/cpu \ | |
| && pip install --no-cache-dir -r requirements.txt | |
| # Copy app code | |
| COPY . . | |
| # Create chroma directory | |
| RUN mkdir -p /app/chroma_db | |
| # Create non-root user | |
| RUN useradd -m appuser && chown -R appuser:appuser /app | |
| USER appuser | |
| # Hugging Face Spaces / FastAPI default | |
| EXPOSE 7860 | |
| # Healthcheck (no extra Python deps needed) | |
| HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| # Run app | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |