Skip to content

Commit 8e90caa

Browse files
committed
build: print error if BuildKit/non-BuildKit-specific flags are used
With this patch, the `--progress`, `--secret`, `--ssh`, and `--output` flags trigger an error when trying to use without BuildKit enabled; DOCKER_BUILDKIT=0 docker build --progress=plain . --progress is only supported with BuildKit enabled. Enable BuildKit with DOCKER_BUILDKIT=1 DOCKER_BUILDKIT=0 docker build --output=foo . --output is only supported with BuildKit enabled. Enable BuildKit with DOCKER_BUILDKIT=1 Likewise, options that are not supported yet by BuildKit, now trigger an error: DOCKER_BUILDKIT=1 docker build --memory=500M . --memory is not supported with BuildKit enabled. Disable BuildKit with DOCKER_BUILDKIT=0 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 8361e66 commit 8e90caa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

cmd/docker/docker.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,16 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
420420
if _, ok := f.Annotations["experimentalCLI"]; ok && !details.ClientInfo().HasExperimental {
421421
errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker cli with experimental cli features enabled`, f.Name))
422422
}
423-
// buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case
423+
if _, ok := f.Annotations["buildkit"]; ok {
424+
if v, _ := command.BuildKitEnabled(details.ServerInfo()); !v {
425+
errs = append(errs, fmt.Sprintf(`"--%s" is only supported with BuildKit enabled. Enable BuildKit with DOCKER_BUILDKIT=1`, f.Name))
426+
}
427+
}
428+
if _, ok := f.Annotations["no-buildkit"]; ok {
429+
if v, _ := command.BuildKitEnabled(details.ServerInfo()); v {
430+
errs = append(errs, fmt.Sprintf(`"--%s" is not supported with BuildKit enabled. Disable BuildKit with DOCKER_BUILDKIT=0`, f.Name))
431+
}
432+
}
424433
})
425434
if len(errs) > 0 {
426435
return errors.New(strings.Join(errs, "\n"))

0 commit comments

Comments
 (0)