Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: pass BuildOptions around explicitly & fix multi-platform issues #10956

Merged
merged 1 commit into from
Sep 1, 2023

Conversation

milas
Copy link
Contributor

@milas milas commented Aug 31, 2023

What I did
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.

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
a chipmunk with its cheeks stuffed full

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]>
@milas milas requested a review from a team August 31, 2023 20:55
@milas milas self-assigned this Aug 31, 2023
@milas milas requested review from nicksieger, ndeloof, StefanScherer, ulyssessouza, glours and laurazard and removed request for a team August 31, 2023 20:56
@codecov
Copy link

codecov bot commented Aug 31, 2023

Codecov Report

Patch coverage: 75.20% and project coverage change: -0.02% ⚠️

Comparison is base (407a0d5) 58.29% compared to head (4c0d2a9) 58.27%.

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     
Files Changed Coverage Δ
cmd/compose/create.go 49.47% <0.00%> (-1.62%) ⬇️
pkg/api/api.go 28.84% <ø> (-13.47%) ⬇️
pkg/compose/run.go 55.45% <0.00%> (ø)
cmd/compose/up.go 67.40% <62.50%> (-0.87%) ⬇️
cmd/compose/run.go 69.62% <68.96%> (-0.91%) ⬇️
pkg/compose/build.go 78.86% <72.41%> (+3.14%) ⬆️
cmd/compose/compose.go 70.73% <75.00%> (-0.17%) ⬇️
cmd/compose/options.go 89.65% <89.65%> (ø)
cmd/compose/build.go 83.95% <100.00%> (+0.61%) ⬆️
pkg/compose/create.go 59.24% <100.00%> (+0.29%) ⬆️
... and 1 more

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants