chore(ci): optimize Dockerfile layer order to cache Python dependency installation #10847
+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