Merge pull request #5178 from thaJeztah/buildkit_windows

build: allow BuildKit to be used on Windows daemons that advertise it
This commit is contained in:
Sebastiaan van Stijn 2024-06-20 18:46:41 +02:00 committed by GitHub
commit b83cf582cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 8 deletions

View File

@ -184,9 +184,18 @@ func (cli *DockerCli) BuildKitEnabled() (bool, error) {
if _, ok := aliasMap["builder"]; ok { if _, ok := aliasMap["builder"]; ok {
return true, nil return true, nil
} }
// otherwise, assume BuildKit is enabled but
// not if wcow reported from server side si := cli.ServerInfo()
return cli.ServerInfo().OSType != "windows", nil if si.BuildkitVersion == types.BuilderBuildKit {
// The daemon advertised BuildKit as the preferred builder; this may
// be either a Linux daemon or a Windows daemon with experimental
// BuildKit support enabled.
return true, nil
}
// otherwise, assume BuildKit is enabled for Linux, but disabled for
// Windows / WCOW, which does not yet support BuildKit by default.
return si.OSType != "windows", nil
} }
// HooksEnabled returns whether plugin hooks are enabled. // HooksEnabled returns whether plugin hooks are enabled.

View File

@ -9,6 +9,7 @@ import (
pluginmanager "github.com/docker/cli/cli-plugins/manager" pluginmanager "github.com/docker/cli/cli-plugins/manager"
"github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -74,14 +75,23 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
return args, osargs, nil, nil return args, osargs, nil, nil
} }
// wcow build command must use the legacy builder if !useBuilder {
// if not opt-in through a builder component // Builder is not explicitly configured as an alias for buildx.
if !useBuilder && dockerCli.ServerInfo().OSType == "windows" { // Detect whether we should use BuildKit, or fallback to the
return args, osargs, nil, nil // legacy builder.
if si := dockerCli.ServerInfo(); si.BuildkitVersion != types.BuilderBuildKit && si.OSType == "windows" {
// The daemon didn't advertise BuildKit as the preferred builder,
// so use the legacy builder, which is still the default for
// Windows / WCOW.
return args, osargs, nil, nil
}
} }
if buildKitDisabled { if buildKitDisabled {
// display warning if not wcow and continue // When using a Linux daemon, print a warning that the legacy builder
// is deprecated. For Windows / WCOW, BuildKit is still experimental,
// so we don't print this warning, even if the daemon advertised that
// it supports BuildKit.
if dockerCli.ServerInfo().OSType != "windows" { if dockerCli.ServerInfo().OSType != "windows" {
_, _ = fmt.Fprintf(dockerCli.Err(), "%s\n\n", buildkitDisabledWarning) _, _ = fmt.Fprintf(dockerCli.Err(), "%s\n\n", buildkitDisabledWarning)
} }