build: pass BuildOptions around explicitly & fix multi-platform issues#10956
Merged
ndeloof merged 1 commit intodocker:mainfrom Sep 1, 2023
Merged
build: pass BuildOptions around explicitly & fix multi-platform issues#10956ndeloof merged 1 commit intodocker:mainfrom
ndeloof merged 1 commit intodocker:mainfrom
Conversation
The big change here is to pass around an explicit `*BuildOptions` object
as part of Compose operations like `up` & `run` that may or may not do
builds. If the options object is `nil`, 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 set `service.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 now
* It was possible for Compose to build an image for one platform and
then try to run it for a different platform (and fail)
* Errors are no longer returned if a local image exists but for the
wrong platform - the correct platform will be fetched/built (if
possible).
Because there's a LOT of subtlety and tricky logic here, I've also tried
to add an excessive amount of explanatory comments.
Signed-off-by: Milas Bowman <[email protected]>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #10956 +/- ##
==========================================
- Coverage 58.29% 58.27% -0.02%
==========================================
Files 123 124 +1
Lines 10884 10906 +22
==========================================
+ Hits 6345 6356 +11
- Misses 3917 3921 +4
- Partials 622 629 +7
☔ View full report in Codecov by Sentry. |
ndeloof
approved these changes
Sep 1, 2023
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 I did
The big change here is to pass around an explicit
*BuildOptionsobject as part of Compose operations likeup&runthat 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
upfor watch. This was broken and tricky to accomplish because various parts of the Compose APIs mutate the*Projectfor convenience in ways that make it unusable afterwards. (For example, it might setservice.Build = nilbecause 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_PLATFORMwas 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
