perf(ci): use stage aliasing to skip Rust recompilation in build-agents#1227
Open
chaodu-agent wants to merge 2 commits into
Open
perf(ci): use stage aliasing to skip Rust recompilation in build-agents#1227chaodu-agent wants to merge 2 commits into
chaodu-agent wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
16c206d to
b3dac9e
Compare
b3dac9e to
aef0681
Compare
This comment has been minimized.
This comment has been minimized.
Refactor Dockerfile.unified to use BuildKit dependency pruning:
- Rename builder stage to local_builder (actual compilation)
- Add global ARG BUILDER_IMAGE=local_builder (before first FROM)
- Add builder alias stage (FROM ${BUILDER_IMAGE} AS builder)
- When BUILDER_IMAGE is overridden in CI, BuildKit prunes local_builder
- All 14 agent targets remain unchanged (COPY --from=builder)
- Align build-operator.yml and smoke-test-unified.yml
- Remove redundant cache-from in build-agents jobs
This eliminates redundant Rust compilation in build-agents jobs,
reducing each variant build from 6-14 min to <1 min.
Closes #1224
aef0681 to
6eb6298
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The PR description claimed a test -x check existed in the alias stage but it was missing. Add it to catch missing binaries early when using a prebuilt registry image.
Collaborator
Author
|
LGTM ✅ — Clean implementation of BuildKit stage aliasing to eliminate redundant Rust compilation in CI. What This PR DoesEliminates redundant Rust recompilation in How It Works
Findings
What's Good (🟢)
Baseline Check
|
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.
What problem does this solve?
Each
build-agentsmatrix job recompiles the entire Rust binary from scratch (6-14 min per job), despite theBUILDER_IMAGEmechanism designed to reuse thebuild-coreoutput. This wastes ~28 redundant compilations per build run.Closes #1224
Prior Art & Industry Research
BuildKit dependency pruning: BuildKit evaluates the stage DAG at build time and skips any stage that has no downstream dependents in the current build target. This is standard BuildKit behavior documented in the Docker multi-stage build docs.
Stage aliasing pattern: Using
FROM ${ARG} AS aliasto dynamically swap between a local build stage and a prebuilt registry image is a well-established pattern in CI-optimized Dockerfiles.Proposed Solution
Use stage aliasing + BuildKit dependency pruning:
local_builder(actual Rust compilation)builderalias stage:FROM ${BUILDER_IMAGE} AS builderBUILDER_IMAGEdefaults tolocal_builder(local dev) or is overridden to the registry image (CI)local_builderentirely — zero compilationCOPY --from=builderunchanged — zero regression riskAdditionally:
build-coreworkflow target updated tolocal_buildercache-frominbuild-agents(no longer needed)test -x) in the alias stageWhy this approach?
COPY --from=builder, eliminating regression riskdocker build --target kiro .works exactly as beforeAlternatives Considered
COPY --from=prebuilt— requires touching 14 targets, higher regression risk, breaks local dev withoutBUILDER_IMAGEcache-from type=registry— fragile, cache invalidation too sensitive to context differencesTest Plan
docker build --target kiro .works locally (exerciseslocal_builderpath)docker build --target local_builder .produces builder image with all 3 binariesbuild-agentslogs show nocargo buildexecution whenBUILDER_IMAGEis setDiscussed and agreed by the full 法師 team in Discord thread.