Skip to content

Commit 6844a06

Browse files
fix: avoid dependency rebuild on version-only bumps in Docker
Add a prep stage that normalizes the root package version to 0.0.0 so BuildKit's content-based caching keeps the dependency layer cached when only the version in Cargo.toml/Cargo.lock changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bf528e4 commit 6844a06

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
- Docker dependency cache now survives version-only bumps by normalizing the root package version in a preparatory build stage.
12+
1013
## [1.3.0] - 2026-03-12
1114

1215
### Added

Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
# Normalize root package version so the dependency cache survives version-only bumps.
2+
# BuildKit uses content-based caching for COPY --from; the sed output is identical
3+
# when only the version changed, so the expensive cargo build layer stays cached.
4+
FROM rust:1.88-alpine AS deps
5+
WORKDIR /src
6+
COPY Cargo.toml Cargo.lock ./
7+
RUN sed -i '/^name = "initium"/{n;s/^version = ".*"/version = "0.0.0"/;}' Cargo.toml && \
8+
sed -i '/^name = "initium"/{n;s/^version = ".*"/version = "0.0.0"/;}' Cargo.lock
9+
110
FROM rust:1.88-alpine AS builder
211
ARG VERSION=dev
312
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static perl
413
WORKDIR /src
5-
COPY Cargo.toml Cargo.lock ./
14+
COPY --from=deps /src/Cargo.toml /src/Cargo.lock ./
615
RUN mkdir src && echo 'fn main() {}' > src/main.rs && \
716
cargo build --release && \
817
rm -rf src target/release/deps/initium* target/release/initium*

jyq.Dockerfile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
# Normalize root package version so the dependency cache survives version-only bumps.
2+
# BuildKit uses content-based caching for COPY --from; the sed output is identical
3+
# when only the version changed, so the expensive cargo build layer stays cached.
4+
FROM rust:1.88-alpine AS deps
5+
WORKDIR /src
6+
COPY Cargo.toml Cargo.lock ./
7+
RUN sed -i '/^name = "initium"/{n;s/^version = ".*"/version = "0.0.0"/;}' Cargo.toml && \
8+
sed -i '/^name = "initium"/{n;s/^version = ".*"/version = "0.0.0"/;}' Cargo.lock
9+
110
FROM rust:1.88-alpine AS builder
211
ARG VERSION=dev
312
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static perl
413
WORKDIR /src
5-
COPY Cargo.toml Cargo.lock ./
14+
COPY --from=deps /src/Cargo.toml /src/Cargo.lock ./
615
RUN mkdir src && echo 'fn main() {}' > src/main.rs && \
716
cargo build --release && \
817
rm -rf src target/release/deps/initium* target/release/initium*

0 commit comments

Comments
 (0)