perf(docker): move version ARG below cached layers to fix cache invalidation#385
Merged
perf(docker): move version ARG below cached layers to fix cache invalidation#385
Conversation
…idation The OPENSHELL_CARGO_VERSION build arg contains a git commit hash that changes on every build (e.g. 0.0.7-dev.11+g085b131ae). Declaring this ARG near the top of each Dockerfile invalidated every layer below it -- including expensive dependency installs, toolchain setup, and the Rust dependency pre-build step -- on every single commit. Move the ARG declaration to just before the RUN that actually uses it so upstream layers stay cached. This recovers ~5-6 minutes per build on the gateway image (from ~9m back toward ~2-3m) and similarly improves cluster, CLI, and Python wheel builds. Also removes unused OPENSHELL_IMAGE_TAG ARG from cli-macos, python-wheels, and python-wheels-macos Dockerfiles.
drew
approved these changes
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix Docker layer cache invalidation caused by
ARG OPENSHELL_CARGO_VERSIONbeing declared near the top of each Dockerfile. Since the version includes a git commit hash (e.g.0.0.7-dev.11+g085b131ae), it changes on every build and invalidates all downstream layers — including expensive dependency installs, toolchain setup, and Rust dependency pre-builds.Related Issue
N/A — discovered via CI timing analysis.
Changes
ARG OPENSHELL_CARGO_VERSIONfrom the top of each builder stage to just before theRUNthat uses it, in all 5 Dockerfiles:Dockerfile.gatewayDockerfile.clusterDockerfile.cli-macosDockerfile.python-wheelsDockerfile.python-wheels-macosARG OPENSHELL_IMAGE_TAGfromDockerfile.cli-macos,Dockerfile.python-wheels, andDockerfile.python-wheels-macosContext
2-week bisect of the
build-gateway / Build gatewayCI job showed two regressions:68525bb8addedARG OPENSHELL_CARGO_VERSIONat top of stageExpected improvement: ~5-6 minutes recovered on gateway builds by preserving layer cache for dependency installation, toolchain setup, and the dependency pre-build step.
Testing
mise run pre-commitpasses (two pre-existing failures unrelated to this change: port-8080-in-use integration test, missing license headers on 3 unrelated files)Checklist