chore(ci): optimize Dockerfile layer order to cache Python dependency installation
CI / lint (pull_request) Successful in 1m3s
CI / build (pull_request) Successful in 42s
CI / quality (pull_request) Successful in 1m13s
CI / typecheck (pull_request) Successful in 1m23s
CI / push-validation (pull_request) Successful in 24s
CI / helm (pull_request) Successful in 36s
CI / security (pull_request) Successful in 1m38s
CI / integration_tests (pull_request) Successful in 4m8s
CI / e2e_tests (pull_request) Successful in 5m11s
CI / unit_tests (pull_request) Successful in 7m27s
CI / docker (pull_request) Successful in 2m43s
CI / coverage (pull_request) Successful in 12m6s
CI / status-check (pull_request) Successful in 3s
CI / coverage (push) Blocked by required conditions
CI / docker (push) Blocked by required conditions
CI / status-check (push) Blocked by required conditions
CI / push-validation (push) Successful in 24s
CI / helm (push) Successful in 31s
CI / benchmark-publish (pull_request) Has been skipped
CI / build (push) Failing after 15m55s
CI / e2e_tests (push) Failing after 15m56s
CI / integration_tests (push) Failing after 15m58s
CI / unit_tests (push) Failing after 15m58s
CI / quality (push) Failing after 15m58s
CI / security (push) Failing after 15m58s
CI / typecheck (push) Failing after 16m0s
CI / lint (push) Failing after 16m2s
CI / benchmark-regression (push) Has been skipped
CI / benchmark-publish (push) Has started running
CI / benchmark-regression (pull_request) Successful in 1h3m8s
CI / lint (pull_request) Successful in 1m3s
CI / build (pull_request) Successful in 42s
CI / quality (pull_request) Successful in 1m13s
CI / typecheck (pull_request) Successful in 1m23s
CI / push-validation (pull_request) Successful in 24s
CI / helm (pull_request) Successful in 36s
CI / security (pull_request) Successful in 1m38s
CI / integration_tests (pull_request) Successful in 4m8s
CI / e2e_tests (pull_request) Successful in 5m11s
CI / unit_tests (pull_request) Successful in 7m27s
CI / docker (pull_request) Successful in 2m43s
CI / coverage (pull_request) Successful in 12m6s
CI / status-check (pull_request) Successful in 3s
CI / coverage (push) Blocked by required conditions
CI / docker (push) Blocked by required conditions
CI / status-check (push) Blocked by required conditions
CI / push-validation (push) Successful in 24s
CI / helm (push) Successful in 31s
CI / benchmark-publish (pull_request) Has been skipped
CI / build (push) Failing after 15m55s
CI / e2e_tests (push) Failing after 15m56s
CI / integration_tests (push) Failing after 15m58s
CI / unit_tests (push) Failing after 15m58s
CI / quality (push) Failing after 15m58s
CI / security (push) Failing after 15m58s
CI / typecheck (push) Failing after 16m0s
CI / lint (push) Failing after 16m2s
CI / benchmark-regression (push) Has been skipped
CI / benchmark-publish (push) Has started running
CI / benchmark-regression (pull_request) Successful in 1h3m8s
Reorder COPY and RUN instructions in both Dockerfile and Dockerfile.server to leverage Docker's layer caching for the dependency installation step. Previously, pyproject.toml, README.md, and src/ were all copied together before running uv pip install, meaning any source code change would invalidate the dependency layer cache and force a full reinstall. The new pattern copies only the dependency manifests (pyproject.toml and uv.lock) first, installs the build tool in a cached layer, then copies README.md and src/ for the actual wheel build. This ensures the uv pip install step is only re-executed when pyproject.toml or uv.lock change, not on every source code change. ISSUES CLOSED: #1667
This commit was merged in pull request #10847.
This commit is contained in:
+12
-4
@@ -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
|
||||
|
||||
+10
-4
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user