diff --git a/Dockerfile b/Dockerfile index eb6b1d466..ae5d61adb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,13 +12,21 @@ COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv # Set up working directory WORKDIR /app -# Copy project metadata and source code -COPY pyproject.toml README.md ./ +# Copy dependency manifests first to leverage Docker layer caching. +# The expensive dependency installation step is only re-executed when +# pyproject.toml or uv.lock change, not on every source code change. +COPY pyproject.toml uv.lock ./ + +# Install build tool — this layer is cached as long as pyproject.toml +# and uv.lock remain unchanged. +RUN uv pip install --system build + +# Copy remaining source files needed for the wheel build. +COPY README.md ./ COPY src/ ./src/ # Build wheel -RUN uv pip install --system build && \ - python -m build --wheel --outdir /dist +RUN python -m build --wheel --outdir /dist # Runtime stage FROM python:3.13-slim diff --git a/Dockerfile.server b/Dockerfile.server index a6d3ba482..65db5d24b 100644 --- a/Dockerfile.server +++ b/Dockerfile.server @@ -22,13 +22,19 @@ COPY --from=ghcr.io/astral-sh/uv:0.8.0 /uv /usr/local/bin/uv WORKDIR /app -# Copy project metadata and source code -COPY pyproject.toml README.md ./ -COPY src/ ./src/ +# Copy dependency manifests first to leverage Docker layer caching. +# The expensive dependency installation step is only re-executed when +# pyproject.toml or uv.lock change, not on every source code change. +COPY pyproject.toml uv.lock ./ -# Install build tool (separate layer for better caching) +# Install build tool (separate layer for better caching) — this layer is +# cached as long as pyproject.toml and uv.lock remain unchanged. RUN uv pip install --system build +# Copy remaining source files needed for the wheel build. +COPY README.md ./ +COPY src/ ./src/ + # Build wheel RUN python -m build --wheel --outdir /dist