Shashiguduri/github-code-explainer
0
1# ── Stage 1: builder ──────────────────────────────────────────────────────────2FROM python:3.11-slim AS builder3 4WORKDIR /app5 6# Install build deps7RUN apt-get update && apt-get install -y --no-install-recommends \8 build-essential git curl \9 && rm -rf /var/lib/apt/lists/*10 11# Install Python dependencies12COPY requirements.txt .13RUN pip install --no-cache-dir --upgrade pip \14 && pip install --no-cache-dir -r requirements.txt15 16# ── Pre-download the embedding model into the image ───────────────────────────17# This means the model is baked into the Docker layer — no HF download at18# runtime, and no memory spike during startup.19RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('BAAI/bge-small-en')"20 21# ── Stage 2: runtime ──────────────────────────────────────────────────────────22FROM python:3.11-slim23 24WORKDIR /app25 26# Copy installed packages from builder27COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages28COPY --from=builder /usr/local/bin /usr/local/bin29# Copy the cached HF model (stored in root's home during build)30COPY --from=builder /root/.cache /root/.cache31 32# Copy application source33COPY . .34 35# HuggingFace Spaces exposes port 7860 by default36ENV PORT=786037EXPOSE 786038 39# Run the FastAPI app40CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]41 