# ──────────────────────────────────────────────────────────────────────────── # Dockerfile for FastAPI + RAG (with pre-created writable chroma_db_users) # ──────────────────────────────────────────────────────────────────────────── FROM python:3.10-slim # 1) Install system packages for building any native extensions RUN apt-get update && \ apt-get install -y --no-install-recommends \ build-essential \ git \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # 2) Copy requirements.txt first so pip layers can be cached COPY requirements.txt . # 3) Install PyTorch CPU + the rest of your Python deps RUN pip install --upgrade pip && \ pip install --no-cache-dir torch==2.1.2+cpu --index-url https://download.pytorch.org/whl/cpu && \ pip install --no-cache-dir -r requirements.txt # 4) Pre-create the HF cache folder and chroma_db_users folder, and make them writable RUN mkdir -p /app/hf_cache && chmod 777 /app/hf_cache && \ mkdir -p /app/chroma_db_users && chmod 777 /app/chroma_db_users # 5) Tell all HuggingFace libs to use /app/hf_cache instead of .cache ENV HF_HOME=/app/hf_cache ENV TRANSFORMERS_CACHE=/app/hf_cache ENV HF_DATASETS_CACHE=/app/hf_cache ENV HF_METRICS_CACHE=/app/hf_cache ENV SENTENCE_TRANSFORMERS_CACHE=/app/hf_cache # 6) Copy the rest of your application code COPY . . # 7) Expose the default HF Spaces port (7860) EXPOSE 7860 # 8) Launch Uvicorn against app.py (which defines `app = FastAPI()`) CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]