|
7 | 7 | "os" |
8 | 8 | "path/filepath" |
9 | 9 | "runtime" |
| 10 | + "strconv" |
10 | 11 | "strings" |
11 | 12 | "time" |
12 | 13 |
|
@@ -58,6 +59,7 @@ type Cli interface { |
58 | 59 | ManifestStore() manifeststore.Store |
59 | 60 | RegistryClient(bool) registryclient.RegistryClient |
60 | 61 | ContentTrustEnabled() bool |
| 62 | + BuildKitEnabled() (bool, error) |
61 | 63 | ContextStore() store.Store |
62 | 64 | CurrentContext() string |
63 | 65 | DockerEndpoint() docker.Endpoint |
@@ -167,6 +169,26 @@ func (cli *DockerCli) ContentTrustEnabled() bool { |
167 | 169 | return cli.contentTrust |
168 | 170 | } |
169 | 171 |
|
| 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 | + |
170 | 192 | // ManifestStore returns a store for local manifests |
171 | 193 | func (cli *DockerCli) ManifestStore() manifeststore.Store { |
172 | 194 | // TODO: support override default location from config file |
|
0 commit comments