FROM python:3.11-slim # 1. System setup RUN apt-get update && apt-get install -y \ git \ && rm -rf /var/lib/apt/lists/* # 2. Create User (HF expects ID 1000) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 WORKDIR $HOME/app # 3. Cache Dependencies (The "Fast Build" trick) # We copy ONLY requirements first so this layer stays cached # unless you change your requirements.txt file. COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # 4. Copy Project Files COPY --chown=user . . # 5. Safety Net for Directories RUN mkdir -p root/network root/db root/api # 6. Port Configuration # HF ignores EXPOSE, but it's good practice. # The CMD below is what actually matters. EXPOSE 7860 # 7. Launch CMD ["uvicorn", "root.server:app", "--host", "0.0.0.0", "--port", "7860"]