FROM python:3.12-slim # 1. Retrieve uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv # System dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Setup non-root user RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR $HOME/app # --- PHASE 1: Installing Dependencies (Cached) --- # Copy only configuration files to leverage Docker cache COPY --chown=user pyproject.toml uv.lock ./ # Create the venv and install dependencies from lockfile # --frozen: ERROR if lockfile is not synchronized with toml (security) # --no-install-project: Install only libraries RUN uv sync --frozen --no-install-project --extra api # Add the venv to PATH ENV PATH="$HOME/app/.venv/bin:$PATH" # --- PHASE 2: Installing Source Code --- COPY --chown=user nygaardcodecommentclassification ./nygaardcodecommentclassification COPY --chown=user app.py ./ # Re-run sync to install the current package # Since dependencies are cached above, this step is instantaneous. RUN uv sync --frozen --extra api # Expose port EXPOSE 7860 # Run uvicorn on port 7860 CMD ["uv", "run", "app.py"]