From e38e6c51ffb55405321038dfcf3a477faeddbf77 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 24 Feb 2022 17:57:47 +0100 Subject: [PATCH 1/2] bring back and expose BuildKitEnabled func Signed-off-by: CrazyMax --- cli/command/cli.go | 22 ++++++++++++++++++++++ internal/test/cli.go | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/cli/command/cli.go b/cli/command/cli.go index c01a66d886e3..1b162a832665 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "runtime" + "strconv" "strings" "time" @@ -58,6 +59,7 @@ type Cli interface { ManifestStore() manifeststore.Store RegistryClient(bool) registryclient.RegistryClient ContentTrustEnabled() bool + BuildKitEnabled() (bool, error) ContextStore() store.Store CurrentContext() string DockerEndpoint() docker.Endpoint @@ -167,6 +169,26 @@ func (cli *DockerCli) ContentTrustEnabled() bool { return cli.contentTrust } +// BuildKitEnabled returns buildkit is enabled or not. +func (cli *DockerCli) BuildKitEnabled() (bool, error) { + // use DOCKER_BUILDKIT env var value if set + if v, ok := os.LookupEnv("DOCKER_BUILDKIT"); ok { + enabled, err := strconv.ParseBool(v) + if err != nil { + return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value") + } + return enabled, nil + } + // if a builder alias is defined, we are using BuildKit + aliasMap := cli.ConfigFile().Aliases + if _, ok := aliasMap["builder"]; ok { + return true, nil + } + // otherwise, assume BuildKit is enabled but + // not if wcow reported from server side + return cli.ServerInfo().OSType != "windows", nil +} + // ManifestStore returns a store for local manifests func (cli *DockerCli) ManifestStore() manifeststore.Store { // TODO: support override default location from config file diff --git a/internal/test/cli.go b/internal/test/cli.go index fb1397f397a7..93ed3abe2173 100644 --- a/internal/test/cli.go +++ b/internal/test/cli.go @@ -215,3 +215,8 @@ func (c *FakeCli) ContentTrustEnabled() bool { func EnableContentTrust(c *FakeCli) { c.contentTrust = true } + +// BuildKitEnabled on the fake cli +func (c *FakeCli) BuildKitEnabled() (bool, error) { + return true, nil +} From e7a8748b939fbf7798352cff1e0b87ef26bf0002 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 23 Feb 2022 16:20:45 +0100 Subject: [PATCH 2/2] build: use legacy builder for wcow if not opt-in with a builder component Signed-off-by: CrazyMax --- cmd/docker/builder.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/docker/builder.go b/cmd/docker/builder.go index 03d6055b8e57..31c6076046c0 100644 --- a/cmd/docker/builder.go +++ b/cmd/docker/builder.go @@ -41,8 +41,7 @@ func newBuilderError(warn bool, err error) error { } func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []string) ([]string, []string, error) { - var useLegacy bool - var useBuilder bool + var useLegacy, useBuilder bool // check DOCKER_BUILDKIT env var is present and // if not assume we want to use the builder component @@ -73,6 +72,12 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st return args, osargs, nil } + // wcow build command must use the legacy builder + // if not opt-in through a builder component + if !useBuilder && dockerCli.ServerInfo().OSType == "windows" { + return args, osargs, nil + } + if useLegacy { // display warning if not wcow and continue if dockerCli.ServerInfo().OSType != "windows" {