Skip to content

Commit 7b153b9

Browse files
committed
api: set default "Builder-Version" to "2" (BuildKit) on Linux
Starting with the 22.06 release, buildx is the default client for docker build, which uses BuildKit as builder. This patch changes the default builder version as advertised by the daemon to "2" (BuildKit), so that pre-22.06 CLIs with BuildKit support (but no buildx installed) also default to using BuildKit when interacting with a 22.06 (or up) daemon. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent cb01202 commit 7b153b9

4 files changed

Lines changed: 84 additions & 11 deletions

File tree

api/server/router/build/build.go

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package build // import "github.com/docker/docker/api/server/router/build"
22

33
import (
4+
"runtime"
5+
46
"github.com/docker/docker/api/server/router"
57
"github.com/docker/docker/api/types"
68
)
@@ -37,17 +39,24 @@ func (r *buildRouter) initRoutes() {
3739
}
3840
}
3941

40-
// BuilderVersion derives the default docker builder version from the config
41-
// Note: it is valid to have BuilderVersion unset which means it is up to the
42-
// client to choose which builder to use.
42+
// BuilderVersion derives the default docker builder version from the config.
43+
//
44+
// The default on Linux is version "2" (BuildKit), but the daemon can be
45+
// configured to recommend version "1" (classic Builder). Windows does not
46+
// yet support BuildKit for native Windows images, and uses "1" (classic builder)
47+
// as a default.
48+
//
49+
// This value is only a recommendation as advertised by the daemon, and it is
50+
// up to the client to choose which builder to use.
4351
func BuilderVersion(features map[string]bool) types.BuilderVersion {
44-
var bv types.BuilderVersion
45-
if v, ok := features["buildkit"]; ok {
46-
if v {
47-
bv = types.BuilderBuildKit
48-
} else {
49-
bv = types.BuilderV1
50-
}
52+
// TODO(thaJeztah) move the default to daemon/config
53+
if runtime.GOOS == "windows" {
54+
return types.BuilderV1
55+
}
56+
57+
bv := types.BuilderBuildKit
58+
if v, ok := features["buildkit"]; ok && !v {
59+
bv = types.BuilderV1
5160
}
5261
return bv
5362
}

api/swagger.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8718,7 +8718,17 @@ paths:
87188718
description: "Max API Version the server supports"
87198719
Builder-Version:
87208720
type: "string"
8721-
description: "Default version of docker image builder"
8721+
description: |
8722+
Default version of docker image builder
8723+
8724+
The default on Linux is version "2" (BuildKit), but the daemon
8725+
can be configured to recommend version "1" (classic Builder).
8726+
Windows does not yet support BuildKit for native Windows images,
8727+
and uses "1" (classic builder) as a default.
8728+
8729+
This value is a recommendation as advertised by the daemon, and
8730+
it is up to the client to choose which builder to use.
8731+
default: "2"
87228732
Docker-Experimental:
87238733
type: "boolean"
87248734
description: "If the server is running with experimental mode enabled"

docs/api/version-history.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ keywords: "API, Docker, rcli, REST, documentation"
5353
if they are not set.
5454
* `GET /info` now omits the `KernelMemory` and `KernelMemoryTCP` if they are not
5555
supported by the host or host's configuration (if cgroups v2 are in use).
56+
* `GET /_ping` and `HEAD /_ping` now return `Builder-Version` by default.
57+
This header contains the default builder to use, and is a recommendation as
58+
advertised by the daemon. However, it is up to the client to choose which builder
59+
to use.
60+
61+
The default value on Linux is version "2" (BuildKit), but the daemon can be
62+
configured to recommend version "1" (classic Builder). Windows does not yet
63+
support BuildKit for native Windows images, and uses "1" (classic builder) as
64+
a default.
65+
66+
This change is not versioned, and affects all API versions if the daemon has
67+
this patch.
5668
* `GET /_ping` and `HEAD /_ping` now return a `Swarm` header, which allows a
5769
client to detect if Swarm is enabled on the daemon, without having to call
5870
additional endpoints.

integration/system/ping_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ package system // import "github.com/docker/docker/integration/system"
33
import (
44
"context"
55
"net/http"
6+
"os"
7+
"path/filepath"
8+
"runtime"
69
"strings"
710
"testing"
811

12+
"github.com/docker/docker/api/types"
913
"github.com/docker/docker/api/types/swarm"
1014
"github.com/docker/docker/api/types/versions"
1115
"github.com/docker/docker/testutil/daemon"
@@ -93,6 +97,44 @@ func TestPingSwarmHeader(t *testing.T) {
9397
})
9498
}
9599

100+
func TestPingBuilderHeader(t *testing.T) {
101+
skip.If(t, testEnv.IsRemoteDaemon)
102+
skip.If(t, testEnv.DaemonInfo.OSType == "windows", "cannot spin up additional daemons on windows")
103+
104+
defer setupTest(t)()
105+
d := daemon.New(t)
106+
client := d.NewClientT(t)
107+
defer client.Close()
108+
ctx := context.TODO()
109+
110+
t.Run("default config", func(t *testing.T) {
111+
d.Start(t)
112+
defer d.Stop(t)
113+
114+
var expected = types.BuilderBuildKit
115+
if runtime.GOOS == "windows" {
116+
expected = types.BuilderV1
117+
}
118+
119+
p, err := client.Ping(ctx)
120+
assert.NilError(t, err)
121+
assert.Equal(t, p.BuilderVersion, expected)
122+
})
123+
124+
t.Run("buildkit disabled", func(t *testing.T) {
125+
cfg := filepath.Join(d.RootDir(), "daemon.json")
126+
err := os.WriteFile(cfg, []byte(`{"features": { "buildkit": false }}`), 0644)
127+
assert.NilError(t, err)
128+
d.Start(t, "--config-file", cfg)
129+
defer d.Stop(t)
130+
131+
var expected = types.BuilderV1
132+
p, err := client.Ping(ctx)
133+
assert.NilError(t, err)
134+
assert.Equal(t, p.BuilderVersion, expected)
135+
})
136+
}
137+
96138
func hdr(res *http.Response, name string) string {
97139
val, ok := res.Header[http.CanonicalHeaderKey(name)]
98140
if !ok || len(val) == 0 {

0 commit comments

Comments
 (0)