Skip to content

Commit 4a2920b

Browse files
committed
perf(build): reduce local cache invalidation
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent 01369a7 commit 4a2920b

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

deploy/docker/Dockerfile.cli-macos

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ FROM ${OSXCROSS_IMAGE} AS osxcross
1818

1919
FROM python:3.12-slim AS builder
2020

21+
ARG OPENSHELL_IMAGE_TAG
2122
ARG CARGO_TARGET_CACHE_SCOPE=default
2223

2324
ENV PATH="/root/.cargo/bin:/usr/local/bin:/osxcross/bin:${PATH}"
@@ -103,8 +104,6 @@ RUN touch crates/openshell-cli/src/main.rs \
103104
crates/openshell-core/build.rs \
104105
proto/*.proto
105106

106-
# Declare version ARG here (not earlier) so the git-hash-bearing value does not
107-
# invalidate the expensive dependency-build layers above on every commit.
108107
ARG OPENSHELL_CARGO_VERSION
109108
RUN --mount=type=cache,id=cargo-registry-cli-macos,sharing=locked,target=/root/.cargo/registry \
110109
--mount=type=cache,id=cargo-git-cli-macos,sharing=locked,target=/root/.cargo/git \

deploy/docker/Dockerfile.images

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ ARG NVIDIA_CONTAINER_TOOLKIT_VERSION=1.18.2-1
2222
FROM --platform=$BUILDPLATFORM rust:1.88-slim AS rust-builder-base
2323
ARG TARGETARCH
2424
ARG BUILDARCH
25-
ARG OPENSHELL_CARGO_VERSION
2625
ARG CARGO_TARGET_CACHE_SCOPE=default
2726
ARG SCCACHE_MEMCACHED_ENDPOINT
2827

@@ -80,6 +79,7 @@ RUN --mount=type=cache,id=cargo-registry-${TARGETARCH},sharing=locked,target=/us
8079
. cross-build.sh && cargo_cross_build --release -p openshell-server -p openshell-sandbox
8180

8281
FROM rust-deps AS rust-workspace
82+
ARG OPENSHELL_CARGO_VERSION
8383

8484
COPY crates/ crates/
8585

deploy/docker/Dockerfile.python-wheels

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ FROM base AS builder
2828

2929
ARG TARGETARCH
3030
ARG BUILDARCH
31+
ARG OPENSHELL_IMAGE_TAG
3132
ARG CARGO_TARGET_CACHE_SCOPE=default
3233

3334
ARG SCCACHE_MEMCACHED_ENDPOINT
@@ -84,8 +85,6 @@ RUN touch crates/openshell-cli/src/main.rs \
8485
crates/openshell-core/build.rs \
8586
proto/*.proto
8687

87-
# Declare version ARG here (not earlier) so the git-hash-bearing value does not
88-
# invalidate the expensive dependency-build layers above on every commit.
8988
ARG OPENSHELL_CARGO_VERSION
9089
RUN --mount=type=cache,id=cargo-registry-python-wheels-${TARGETARCH},sharing=locked,target=/root/.cargo/registry \
9190
--mount=type=cache,id=cargo-git-python-wheels-${TARGETARCH},sharing=locked,target=/root/.cargo/git \

deploy/docker/Dockerfile.python-wheels-macos

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ FROM ${OSXCROSS_IMAGE} AS osxcross
1212
FROM python:${PYTHON_VERSION}-slim AS builder
1313

1414
ARG TARGETARCH
15+
ARG OPENSHELL_IMAGE_TAG
1516
ARG CARGO_TARGET_CACHE_SCOPE=default
1617

1718
ENV PATH="/root/.cargo/bin:/usr/local/bin:/osxcross/bin:${PATH}"
@@ -91,8 +92,6 @@ RUN touch crates/openshell-cli/src/main.rs \
9192
crates/openshell-core/build.rs \
9293
proto/*.proto
9394

94-
# Declare version ARG here (not earlier) so the git-hash-bearing value does not
95-
# invalidate the expensive dependency-build layers above on every commit.
9695
ARG OPENSHELL_CARGO_VERSION
9796
RUN --mount=type=cache,id=cargo-registry-python-wheels-macos-${TARGETARCH},sharing=locked,target=/root/.cargo/registry \
9897
--mount=type=cache,id=cargo-git-python-wheels-macos-${TARGETARCH},sharing=locked,target=/root/.cargo/git \

tasks/python.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ sha256_16_stdin() {
4545
4646
PLATFORMS=${DOCKER_PLATFORMS:-linux/amd64,linux/arm64}
4747
CARGO_VERSION=${OPENSHELL_CARGO_VERSION:-}
48-
if [ -z "$CARGO_VERSION" ]; then
48+
if [ -z "$CARGO_VERSION" ] && [ -n "${CI:-}" ]; then
4949
CARGO_VERSION=$(uv run python tasks/scripts/release.py get-version --cargo)
5050
fi
5151
@@ -55,11 +55,14 @@ CACHE_SCOPE_INPUT="v1|python-wheels|base|${LOCK_HASH}|${RUST_SCOPE}"
5555
CARGO_TARGET_CACHE_SCOPE=$(printf '%s' "$CACHE_SCOPE_INPUT" | sha256_16_stdin)
5656
5757
VERSION_ARGS=(
58-
--build-arg "OPENSHELL_CARGO_VERSION=${CARGO_VERSION}"
5958
--build-arg "CARGO_TARGET_CACHE_SCOPE=${CARGO_TARGET_CACHE_SCOPE}"
6059
${OPENSHELL_IMAGE_TAG:+--build-arg "OPENSHELL_IMAGE_TAG=${OPENSHELL_IMAGE_TAG}"}
6160
)
6261
62+
if [ -n "$CARGO_VERSION" ]; then
63+
VERSION_ARGS+=(--build-arg "OPENSHELL_CARGO_VERSION=${CARGO_VERSION}")
64+
fi
65+
6366
if ! docker buildx inspect multiarch >/dev/null 2>&1; then
6467
echo "Creating multi-platform buildx builder..."
6568
docker buildx create --name multiarch --use --bootstrap
@@ -171,7 +174,7 @@ sha256_16_stdin() {
171174
172175
CARGO_VERSION=${OPENSHELL_CARGO_VERSION:-}
173176
OSXCROSS_IMAGE_REF=${OSXCROSS_IMAGE:-crazymax/osxcross:latest}
174-
if [ -z "$CARGO_VERSION" ]; then
177+
if [ -z "$CARGO_VERSION" ] && [ -n "${CI:-}" ]; then
175178
CARGO_VERSION=$(uv run python tasks/scripts/release.py get-version --cargo)
176179
fi
177180
@@ -186,8 +189,8 @@ docker build \
186189
-f deploy/docker/Dockerfile.python-wheels-macos \
187190
--target wheels \
188191
--build-arg "OSXCROSS_IMAGE=${OSXCROSS_IMAGE_REF}" \
189-
--build-arg "OPENSHELL_CARGO_VERSION=${CARGO_VERSION}" \
190192
--build-arg "CARGO_TARGET_CACHE_SCOPE=${CARGO_TARGET_CACHE_SCOPE}" \
193+
${CARGO_VERSION:+--build-arg "OPENSHELL_CARGO_VERSION=${CARGO_VERSION}"} \
191194
${OPENSHELL_IMAGE_TAG:+--build-arg "OPENSHELL_IMAGE_TAG=${OPENSHELL_IMAGE_TAG}"} \
192195
--output type=local,dest=target/wheels \
193196
.

tasks/scripts/docker-build-image.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fi
105105
VERSION_ARGS=()
106106
if [[ -n "${OPENSHELL_CARGO_VERSION:-}" ]]; then
107107
VERSION_ARGS=(--build-arg "OPENSHELL_CARGO_VERSION=${OPENSHELL_CARGO_VERSION}")
108-
else
108+
elif [[ -n "${CI:-}" ]]; then
109109
CARGO_VERSION=$(uv run python tasks/scripts/release.py get-version --cargo 2>/dev/null || true)
110110
if [[ -n "${CARGO_VERSION}" ]]; then
111111
VERSION_ARGS=(--build-arg "OPENSHELL_CARGO_VERSION=${CARGO_VERSION}")

0 commit comments

Comments
 (0)