api/server/router/build: BuilderVersion: allow buildkit on Windows

Commit 7b153b9e28 changed the daemon to
advertise the recommended builder to use to V2 (BuildKit) for Linux
daemons, and V1 (Legacy Builder) for Windows daemons. For Linux daemons
we allowed the default to be overridden through the "features" field
in the daemon config (daemon.json), but for Windows we hard-coded it
to be V1, and no option to override.

With work in progress on implementing support for Windows in BuildKit,
we should remove this hardcoded assumption, and allow the default to
be overridden to advertise that BuildKit is supported.

Note that BuildKit on Windows is still very much a "work in progress",
and enabling it in the daemon may not even work, so users should not
try to enable this feature; a warning-level log is added to make it
visible that the feature is enabled.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-06-20 01:15:58 +02:00
parent f4ffeb8c38
commit c6b9bb00f9
2 changed files with 19 additions and 6 deletions

View File

@@ -4,7 +4,7 @@ import (
"runtime"
"github.com/docker/docker/api/server/router"
build2 "github.com/docker/docker/api/types/build"
"github.com/docker/docker/api/types/build"
)
// buildRouter is a router to talk with the build controller
@@ -46,15 +46,22 @@ func (br *buildRouter) initRoutes() {
//
// This value is only a recommendation as advertised by the daemon, and it is
// up to the client to choose which builder to use.
func BuilderVersion(features map[string]bool) build2.BuilderVersion {
func BuilderVersion(features map[string]bool) build.BuilderVersion {
// TODO(thaJeztah) move the default to daemon/config
bv := build.BuilderBuildKit
if runtime.GOOS == "windows" {
return build2.BuilderV1
// BuildKit is not yet the default on Windows.
bv = build.BuilderV1
}
bv := build2.BuilderBuildKit
if v, ok := features["buildkit"]; ok && !v {
bv = build2.BuilderV1
// Allow the features field in the daemon config to override the
// default builder to advertise.
if enable, ok := features["buildkit"]; ok {
if enable {
bv = build.BuilderBuildKit
} else {
bv = build.BuilderV1
}
}
return bv
}

View File

@@ -294,6 +294,12 @@ func (cli *daemonCLI) start(ctx context.Context) (err error) {
return fmt.Errorf("error initializing buildkit: %w", err)
}
if runtime.GOOS == "windows" {
if enabled, ok := d.Features()["buildkit"]; ok && enabled {
log.G(ctx).Warn("Buildkit feature is enabled in the daemon.json configuration file. Support for BuildKit on Windows is experimental, and enabling this feature may not work. Use at your own risk!")
}
}
routers := buildRouters(routerOptions{
features: d.Features,
daemon: d,