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

Set buildx as default builder #3314

Merged
merged 5 commits into from Feb 3, 2022
Merged

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Sep 28, 2021

This is a first part to the effort to migrate users to buildx as the default builder.

tldr;

The default experience will be the same as the current DOCKER_BUILDKIT=1 experience. This was the default experience for Docker Desktop and we are unifying the experience to be the same for Linux distributions as well.

All Docker packages will contain buildx by default. The user does not need to install anything else. If a third-party package distributes CLI today without buildx, it may be necessary to update its release pipeline.

Context

There are currently four different ways that one can build locally with Docker:

  • The legacy builder in Docker Engine: DOCKER_BUILDKIT=0 docker build .
  • BuildKit in Docker Engine: DOCKER_BUILDKIT=1 docker build .
  • Buildx CLI plugin with the Docker driver: docker buildx build .
  • Buildx CLI plugin with the Container driver: docker buildx create && docker buildx build .

The current state not only confuses users who do not understand the differences between our build experiences, it also contradicts with where we are investing our build engineering effort: in Buildx and BuildKit.

What is buildx?

Buildx is a CLI tool that, combined with the server-side component BuildKit, provides Docker's next generation container build system. Buildx is architected so that it can work with different container runtimes through drivers. Some of the drivers (container and kubernetes) use a containerized version of BuildKit which means that the build tool chain can be updated independently of other container tooling.

Key features of buildx include:

  • Multi-platform builds using QEMU binary emulation or native builders
  • Parallel builds across multiple builder nodes
  • Support for different container runtimes (Docker, Kubernetes)
  • Standalone architecture (for container and kubernetes drivers)
  • (Experimental) high-level build tooling with bake

What I did

Forward CLI build command

Docker branded build commands will by default be invoked by buildx client and go to a BuildKit based backend:

  • docker build forwarded to docker buildx build
  • docker image build forwarded to docker buildx build
  • docker builder forwarded to docker buildx

Remove BuildKit implementation

  • Remove BuildKit implementation code and linked build flags (now forwarded to buildx).

DOCKER_BUILDKIT=0 fallback

  • The legacy builder invocation code will remain in CLI for now in a frozen state. If the environment variable is set, it will be used instead.
  • Build triggered this way issue a warning for an unoptimized build (will be replaced with a deprecation message at some point in the future).

Default behavior for WCOW

  • WCOW build command should point to the legacy builder by default. Note that this does not mean Windows clients that should default to buildx but windows containers reported from server-side.

Missing plugin

  • If Buildx plugin is missing or broken, the following message will be displayed and fall back to the legacy builder:
$ docker build .
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
            Install the buildx component to build images with BuildKit:
            https://docs.docker.com/go/buildx/

Sending build context to Docker daemon ...
...
  • But if builder is enforced with DOCKER_BUILDKIT=1 and plugin is missing or broken, cmd will fail:
$ DOCKER_BUILDKIT=1 docker build .
ERROR: BuildKit is enabled but the buildx component is missing or broken.
       Install the buildx component to build images with BuildKit:
       https://docs.docker.com/go/buildx/
  • Add deprecation note entry about legacy builder fallback

Documentation

Update documentation:

How to verify it

$ docker buildx bake binary
$ ./build/docker build .

cc @tonistiigi @thaJeztah @justincormack @mikeparker @chris-crone

closes #3237

Signed-off-by: CrazyMax crazy-max@users.noreply.github.com

cmd/docker/docker.go Outdated Show resolved Hide resolved
@crazy-max crazy-max force-pushed the buildx-default branch 2 times, most recently from 1aa0c06 to fd9759a Compare September 28, 2021 15:37
cmd/docker/buildx.go Outdated Show resolved Hide resolved
cmd/docker/buildx.go Outdated Show resolved Hide resolved
cmd/docker/buildx.go Outdated Show resolved Hide resolved
@crazy-max crazy-max force-pushed the buildx-default branch 6 times, most recently from 4ecdc42 to 1d5ae62 Compare October 5, 2021 14:33
@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2021

Codecov Report

Merging #3314 (16edf8b) into master (5bb88dc) will increase coverage by 0.97%.
The diff coverage is 60.62%.

@@            Coverage Diff             @@
##           master    #3314      +/-   ##
==========================================
+ Coverage   56.36%   57.33%   +0.97%     
==========================================
  Files         304      304              
  Lines       26816    26379     -437     
==========================================
+ Hits        15114    15124      +10     
+ Misses      10782    10329     -453     
- Partials      920      926       +6     

cmd/docker/buildx.go Outdated Show resolved Hide resolved
cmd/docker/buildx.go Outdated Show resolved Hide resolved
cmd/docker/aliases.go Show resolved Hide resolved
cli/command/image/build.go Outdated Show resolved Hide resolved
cli/command/image/build.go Outdated Show resolved Hide resolved
cmd/docker/aliases.go Outdated Show resolved Hide resolved
cmd/docker/builder.go Outdated Show resolved Hide resolved
cmd/docker/builder.go Outdated Show resolved Hide resolved
@crazy-max crazy-max force-pushed the buildx-default branch 2 times, most recently from d2ae311 to fc290ee Compare October 14, 2021 00:20
@tonistiigi
Copy link
Member

@crazy-max Looks like the stderr change broke a test. Just issue with the test assert iiuc

@crazy-max crazy-max force-pushed the buildx-default branch 2 times, most recently from 8464bf7 to 88840a6 Compare February 3, 2022 10:47
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM (left two minor suggestions)

cli/command/image/build.go Outdated Show resolved Hide resolved
cmd/docker/builder.go Outdated Show resolved Hide resolved
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah
Copy link
Member

Bringing this one in (discussed in the maintainers meeting, and @cpuguy83 will complain after release 😂)

@thaJeztah thaJeztah merged commit c780f7c into docker:master Feb 3, 2022
@@ -169,20 +168,6 @@ func (cli *DockerCli) ContentTrustEnabled() bool {
return cli.contentTrust
}

// BuildKitEnabled returns whether buildkit is enabled either through a daemon setting
// or otherwise the client-side DOCKER_BUILDKIT environment variable
func BuildKitEnabled(si ServerInfo) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

docker/compose relies on this to select the builder to be used.
Maybe restore this function as a dumb return true would make more sense?

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the logic was moved inside processBuilder(). Perhaps it makes sense to move that logic back into this function. The default would now be (true) if DOCKER_BUILDKIT is not set?

Wondering if the function also needs to take windows daemon into account 🤔
How exactly is it used in Compose (as in; what does it do if it's "disabled"? or is that only for the Windows case?)

@sudo-bmitch
Copy link
Contributor

Related: moby/moby#42350

@crazy-max crazy-max deleted the buildx-default branch March 18, 2022 07:01
matt9ucci added a commit to matt9ucci/DockerCompletion that referenced this pull request Feb 9, 2023
matt9ucci added a commit to matt9ucci/DockerCompletion that referenced this pull request Feb 9, 2023
jtkech referenced this pull request in OrchardCMS/OrchardCore Dec 4, 2023
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.

None yet