# 1. Use a lightweight Python image FROM python:3.10-slim # 2. Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONPATH=/code \ HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ HF_HOME=/code/.cache # 3. Set working directory WORKDIR /code # 4. Install system dependencies RUN apt-get update && apt-get install -y \ build-essential \ && rm -rf /var/lib/apt/lists/* # 5. Create a non-root user (Hugging Face requirement) RUN useradd -m -u 1000 user RUN mkdir -p /code/.cache && chown -R user:user /code # 6. Switch to the non-root user USER user # 7. Copy requirements and install COPY --chown=user requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --user --upgrade -r /code/requirements.txt # 8. Copy the entire project COPY --chown=user . /code # 9. Start the application EXPOSE 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]