FROM python:3.11-slim WORKDIR /app RUN apt-get update && apt-get install -y --no-install-recommends \ gcc g++ && rm -rf /var/lib/apt/lists/* # Shared package COPY shared/ ./shared/ RUN pip install --no-cache-dir -e ./shared/ # Torch first (heaviest layer — cached unless version changes) RUN pip install --no-cache-dir \ --extra-index-url https://download.pytorch.org/whl/cpu \ "torch>=2.4.0" # Remaining deps COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Pre-download the model inside the image — HF builds have plenty of time & space RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" # App source COPY app/ ./app/ ENV PYTHONUNBUFFERED=1 \ PYTHONPATH=/app \ TRANSFORMERS_CACHE=/app/.cache/hf \ HF_HOME=/app/.cache/hf EXPOSE 7860 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]