# ── Stage 1: Build ──────────────────────────────────────────────────── FROM python:3.11-slim AS builder # Install uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv WORKDIR /app # Copy dependency manifests first (Docker layer caching) COPY pyproject.toml uv.lock ./ # Install production dependencies only — frozen ensures lockfile is respected RUN uv sync --frozen --no-dev --no-install-project # Copy application source COPY src/ src/ COPY README.md ./ # Install the project itself RUN uv sync --frozen --no-dev # ── Stage 2: Runtime ────────────────────────────────────────────────── FROM python:3.11-slim # UV is needed at runtime for 'uv run' COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv WORKDIR /app # Copy the entire virtual environment and source from builder COPY --from=builder /app /app # Port is supplied by the host (Cloud Run: 8080, HF Spaces: 7860). # Default to 8080 for local runs when PORT is unset. ENV PORT=8080 EXPOSE ${PORT} # Shell form so ${PORT} is expanded at runtime by the host environment. CMD ["sh", "-c", "uv run uvicorn backend.main:app --host 0.0.0.0 --port ${PORT:-8080}"]