fix(compose): forward build.target/args and honor image+build (#14)#16
Merged
Conversation
`compose up --build` ignored `build.target` and `build.args` because the compose parser never read those fields, so the orchestrator could not pass them to `container build` — the whole Dockerfile was built instead of stopping at the target stage. Parse both (args supports map and list forms, preserving explicit empty values) and forward them from both `compose up` and `compose build`. A service declaring both `image:` and `build:` previously pulled the `image:` reference from a registry (401) instead of building. Per the Compose spec it must build from context and tag the result with the `image:` name; pull only when there is no build config. The decision is extracted into a pure `ComposeService.resolveImageSource` for testing. Also plumb `--build`/`--no-build` from the CLI into the orchestrator so `--build` forces a rebuild instead of being silently ignored.
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.
Fixes #14.
Problem
mocker compose up --buildignoredservices.<svc>.build.targetfrom the compose file and built the entire Dockerfile (all stages) instead of stopping at the named target. While investigating, two more related bugs surfaced.Root causes
build.target/build.argsdropped at parse time.ComposeBuildhad notarget/argsfields andComposeService.parse()never read them, so the orchestrator had nothing to forward tocontainer build(which already supports--target).image:+build:→ registry pull (401). The orchestrator'sif image { pull } else if build { build }was exclusive, so a service with both pulledimage:from the registry instead of building and tagging — failing with401 Unauthorized(reported in an issue comment).compose up --buildflag never plumbed. The--buildflag was parsed but never reached the orchestrator, so it couldn't force a rebuild.Changes
ComposeFile.swift: addtarget+argstoComposeBuild; parse both (args supports map and listKEY=VALUEforms, preserving explicit empty values likeREQUIRED_TOKEN=). Add a pureComposeService.resolveImageSource(projectName:noBuild:)that decides build-vs-pull per the Compose spec, plusimageMatchesfor the rebuild-skip check.ComposeOrchestrator.swift:startServicenow builds whenbuild:is present (tagging withimage:if set, never pulling), forwardstarget+args, and honorsforceBuild/noBuild.up()acceptsbuild/noBuild.Compose.swift:compose upandcompose createforward--build/--no-build;compose buildforwards compose-filebuild.args(CLI--build-argoverrides) andbuild.target.Tests
10 new unit tests (no container runtime needed) covering the exact bug points:
build.target,build.args(map + list + explicit empty value),image:+build:togetherresolveImageSource: image-only → pull, build-only → build (synthesized tag),image:+build:→ build tagged with image name,--no-build→ pull, empty → noneimageMatchesrepository/tag comparisonFull suite green: 75 tests in 8 suites pass (
swift build+swift test).Note
An end-to-end
compose up --buildagainst the Applecontainerruntime was not run (needs a live daemon and image builds); the fix is verified by unit tests at the parse + decision layers where the bugs lived, plus the existing--targetplumbing inImageManager.build.