Skip to content

Commit e38e6c5

Browse files
committed
bring back and expose BuildKitEnabled func
Signed-off-by: CrazyMax <[email protected]>
1 parent 60283c6 commit e38e6c5

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

cli/command/cli.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"path/filepath"
99
"runtime"
10+
"strconv"
1011
"strings"
1112
"time"
1213

@@ -58,6 +59,7 @@ type Cli interface {
5859
ManifestStore() manifeststore.Store
5960
RegistryClient(bool) registryclient.RegistryClient
6061
ContentTrustEnabled() bool
62+
BuildKitEnabled() (bool, error)
6163
ContextStore() store.Store
6264
CurrentContext() string
6365
DockerEndpoint() docker.Endpoint
@@ -167,6 +169,26 @@ func (cli *DockerCli) ContentTrustEnabled() bool {
167169
return cli.contentTrust
168170
}
169171

172+
// BuildKitEnabled returns buildkit is enabled or not.
173+
func (cli *DockerCli) BuildKitEnabled() (bool, error) {
174+
// use DOCKER_BUILDKIT env var value if set
175+
if v, ok := os.LookupEnv("DOCKER_BUILDKIT"); ok {
176+
enabled, err := strconv.ParseBool(v)
177+
if err != nil {
178+
return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
179+
}
180+
return enabled, nil
181+
}
182+
// if a builder alias is defined, we are using BuildKit
183+
aliasMap := cli.ConfigFile().Aliases
184+
if _, ok := aliasMap["builder"]; ok {
185+
return true, nil
186+
}
187+
// otherwise, assume BuildKit is enabled but
188+
// not if wcow reported from server side
189+
return cli.ServerInfo().OSType != "windows", nil
190+
}
191+
170192
// ManifestStore returns a store for local manifests
171193
func (cli *DockerCli) ManifestStore() manifeststore.Store {
172194
// TODO: support override default location from config file

internal/test/cli.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,8 @@ func (c *FakeCli) ContentTrustEnabled() bool {
215215
func EnableContentTrust(c *FakeCli) {
216216
c.contentTrust = true
217217
}
218+
219+
// BuildKitEnabled on the fake cli
220+
func (c *FakeCli) BuildKitEnabled() (bool, error) {
221+
return true, nil
222+
}

0 commit comments

Comments
 (0)