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

delegate build to buildx bake #11484

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

ndeloof
Copy link
Contributor

@ndeloof ndeloof commented Feb 9, 2024

What I did
Use buildx raw json output (moby/buildkit#4113) so we can implement build as an external command.
Allows user to upgrade buildx and benefits new features/bug fixes without having to wait for compose to bump dependencies
Still relies on buildkit's progress UI, but we technically could redesign the build progress display by processing solver status on our own. If we do, we could fully remove dependency on buildx/buildkit

note: due to docker/buildx#2252, json parsing error must be ignored :'(

(not mandatory) A picture of a cute animal, if possible in relation to what you did
image

@ndeloof ndeloof force-pushed the delegate_build branch 6 times, most recently from 08f256f to a92f4ee Compare February 9, 2024 13:10
ID: "==> ==>",
Status: progress.Done,
Text: fmt.Sprintf(`naming to %s`, options.Tags[0]),
cmd := exec.CommandContext(ctx, "docker", "buildx", "bake", "--file", "-", "--progress", "rawjson", "--metadata-file", metadata.Name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should call buildx in standalone mode to reduce overhead implied by docker command (and in particular docker proxy in DD).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also has implications wrt signal handling, CLI plugin management, etc. In this case we'd have CLI binary -> Compose plugin binary -> CLI binary -> Buildx plugin binary AND between the CLI and Compose and then between the 2nd CLI process and Buildx the CLI would be setting up a socket for plugin communication, etc. Need to think about what the tradeoffs are there/whether we should and what we can do on the CLI side to make this as painless as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes this I already identified, marked this as a Draft to avoid any confusion: there's a bunch of things missing here :)

@ndeloof ndeloof force-pushed the delegate_build branch 4 times, most recently from 8793d51 to 0c01a6f Compare February 9, 2024 14:25
if err != nil {
return "", err
}
cmd := exec.CommandContext(ctx, buildx.Path, "buildx", "bake", "--file", "-", "--progress", "rawjson", "--metadata-file", metadata.Name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Suggested change
cmd := exec.CommandContext(ctx, buildx.Path, "buildx", "bake", "--file", "-", "--progress", "rawjson", "--metadata-file", metadata.Name())
cmd := exec.CommandContext(ctx, buildx.Path, "bake", "--file", "-", "--progress", "rawjson", "--metadata-file", metadata.Name())

Copy link
Contributor Author

@ndeloof ndeloof Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we propagate os.Env, DOCKER_CLI_PLUGIN_ORIGINAL_CLI_COMMAND is set and buildx get confused it's not actually running standalone. Need to exclude this variable to get buildx run standalone

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@luciangabor
Copy link

would compose send to bake x-bakes too? https://docs.docker.com/build/bake/compose-file/
(if yes, I think this should have an "--opt-out" or an "--opt-in")

@ndeloof
Copy link
Contributor Author

ndeloof commented Mar 13, 2024

It could (this PR is 100% experimental) but AFAICT x-bake are not required, as all build features are now part of the compose-spec

@luciangabor
Copy link

It could be quite welcomed, but, when it comes to x-bakes, it's nice to be able to simply build and run with compose and bake with an output that extracts binaries, or set tags for pushes, or ... anything that's not about local dev (albeit it's possible to do that using distinct files)

@ndeloof
Copy link
Contributor Author

ndeloof commented Mar 13, 2024

docker compose build only would support a subset of bake features, typically is REQUIRE an image to be built, as the primary goal is to later run the app (also consider docker compose up --build), so "output that extracts binaries" would make no sense, and should only be used with docker buildx bake.

or set tags for pushes

Already supported if you run docker compose build --push

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

Successfully merging this pull request may close these issues.

None yet

4 participants