File size: 922 Bytes
a4a1ec8 791d677 a4a1ec8 e26fa15 791d677 a4a1ec8 e26fa15 a4a1ec8 791d677 a4a1ec8 e26fa15 a4a1ec8 e26fa15 a4a1ec8 791d677 a4a1ec8 791d677 a4a1ec8 |
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 |
# 1. Use Hugging Face recommended Python image
FROM python:3.9
# 2. Create non-root user (required by Hugging Face Spaces)
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"
# 3. Set working directory
WORKDIR /app
# 4. Install essential system dependencies
# - switched to root temporarily
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc libpq-dev && \
rm -rf /var/lib/apt/lists/*
USER user
# 5. Copy requirements first for caching
COPY --chown=user requirements.txt .
# 6. Upgrade pip & install Python dependencies
RUN python -m pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# 7. Copy the rest of the app code
COPY --chown=user . .
# 8. Expose Hugging Face default port
EXPOSE 7860
# 9. Run Uvicorn server for FastAPI app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]
|