From c6b9bb00f9b8f0fcc37c3ae76cc4b677fe297f2e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 20 Jun 2024 01:15:58 +0200 Subject: [PATCH] api/server/router/build: BuilderVersion: allow buildkit on Windows Commit 7b153b9e28b53779215de209736310f9266b3f2f 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 --- api/server/router/build/build.go | 19 +++++++++++++------ cmd/dockerd/daemon.go | 6 ++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/api/server/router/build/build.go b/api/server/router/build/build.go index 461ab0bcf5..262e0b9e81 100644 --- a/api/server/router/build/build.go +++ b/api/server/router/build/build.go @@ -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 } diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index e4eb5812c7..0ac4036239 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -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,