File size: 979 Bytes
820c4b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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"]
|