FROM python:3.12-slim # curl for the HEALTHCHECK RUN apt-get update && apt-get install -y --no-install-recommends curl && \ apt-get clean && rm -rf /var/lib/apt/lists/* # HuggingFace Spaces runs containers as user 1000 RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONPATH=/home/user/app \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 WORKDIR $HOME/app RUN pip install --no-cache-dir --upgrade pip # Install dependencies first for layer caching COPY --chown=user pyproject.toml README.md $HOME/app/ RUN pip install --no-cache-dir fastapi httpx lxml numpy pandas pydantic pyyaml requests uvicorn yfinance COPY --chown=user src/ $HOME/app/src/ COPY --chown=user configs/ $HOME/app/configs/ COPY --chown=user app.py $HOME/app/ EXPOSE 7860 HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \ CMD curl --fail http://localhost:7860/health || exit 1 CMD ["python", "app.py"]