build: pass BuildOptions around explicitly & fix multi-platform issues #10956
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 I did
The big change here is to pass around an explicit
*BuildOptions
object as part of Compose operations likeup
&run
that may or may not do builds. If the options object isnil
, no builds whatsoever will be attempted.Motivation is to allow for partial rebuilds in the context of an
up
for watch. This was broken and tricky to accomplish because various parts of the Compose APIs mutate the*Project
for convenience in ways that make it unusable afterwards. (For example, it might setservice.Build = nil
because it's not going to build that service right then. But we might still want to build it later!)NOTE: This commit does not actually touch the watch logic. This is all
in preparation to make it possible.
As part of this, a bunch of code moved around and I eliminated a bunch of partially redundant logic, mostly around multi-platform. Several edge cases have been addressed as part of this:
DOCKER_DEFAULT_PLATFORM
was overriding explicitly set platforms in some cases, this is no longer true, and it behaves like the Docker CLI nowBecause there's a LOT of subtlety and tricky logic here, I've also tried to add an excessive amount of explanatory comments.
Related issue
https://docker.atlassian.net/browse/ENV-286
(not mandatory) A picture of a cute animal, if possible in relation to what you did
