Spaces:
Sleeping
Sleeping
# ๐น Base image | |
FROM python:3.10-slim | |
# ๐น Create Hugging Face-compliant non-root user | |
RUN useradd -m -u 1000 user | |
# ๐น Set environment variables | |
ENV HOME=/home/user | |
ENV APP_HOME=/home/user/app | |
ENV HF_HOME=/home/user/.hf_home | |
# ๐น Set working directory | |
WORKDIR $APP_HOME | |
# ๐น Install system dependencies (root) | |
USER root | |
RUN apt-get update && apt-get install -y \ | |
git curl \ | |
&& rm -rf /var/lib/apt/lists/* | |
# ๐น Install Python dependencies | |
COPY --chown=user:user requirements.txt . | |
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt | |
# ๐น Copy app code and give ownership to non-root user | |
COPY --chown=user:user . . | |
# ๐น Ensure HF model cache dir is writable | |
RUN mkdir -p $HF_HOME && chown -R user:user $HF_HOME | |
# ๐น Switch to non-root user (required by HF Spaces) | |
USER user | |
# ๐น Expose the FastAPI port | |
EXPOSE 7860 | |
# ๐น Start your app | |
CMD ["python", "app.py"] | |