davanstrien's picture
davanstrien HF Staff
Optimize Dockerfile: use uv from official image, resolve deps on target platform
dab5e76
raw
history blame contribute delete
961 Bytes
FROM python:3.11-slim
# Install uv from official image (fast, no pip bootstrap needed)
COPY --from=ghcr.io/astral-sh/uv:0.9.30 /uv /bin/uv
ENV HF_HUB_ENABLE_HF_TRANSFER=1
# Install dependencies from requirements.in - resolved on the target platform,
# no cross-compilation flags needed. CPU-only torch via extra index.
COPY requirements.in /tmp/requirements.in
RUN --mount=type=cache,target=/root/.cache/uv \
uv pip install --system \
--extra-index-url https://download.pytorch.org/whl/cpu \
-r /tmp/requirements.in
# Create non-root user (HF Spaces runs as user ID 1000)
RUN useradd -m -u 1000 user
USER user
# Set home and path
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
# Copy application (as user)
COPY --chown=user . .
# Create data directory for dataset download
RUN mkdir -p $HOME/app/data
# HF Spaces expects port 7860
EXPOSE 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]