Compare commits

...

2 Commits

Author SHA1 Message Date
Sebastiaan van Stijn 2b6cc64716
Merge e2986f4467 into ccb3b44fe3 2024-10-01 15:54:35 +02:00
Sebastiaan van Stijn e2986f4467
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>
2020-11-17 11:06:29 +01:00
1 changed files with 10 additions and 1 deletions

View File

@ -568,7 +568,16 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
if _, ok := f.Annotations["experimental"]; ok && !details.ServerInfo().HasExperimental { if _, ok := f.Annotations["experimental"]; ok && !details.ServerInfo().HasExperimental {
errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker daemon with experimental features enabled`, f.Name)) errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker daemon with experimental features enabled`, f.Name))
} }
// buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case if _, ok := f.Annotations["buildkit"]; ok {
if v, _ := command.BuildKitEnabled(details.ServerInfo()); !v {
errs = append(errs, fmt.Sprintf(`"--%s" is only supported with BuildKit enabled. Enable BuildKit with DOCKER_BUILDKIT=1`, f.Name))
}
}
if _, ok := f.Annotations["no-buildkit"]; ok {
if v, _ := command.BuildKitEnabled(details.ServerInfo()); v {
errs = append(errs, fmt.Sprintf(`"--%s" is not supported with BuildKit enabled. Disable BuildKit with DOCKER_BUILDKIT=0`, f.Name))
}
}
}) })
if len(errs) > 0 { if len(errs) > 0 {
return errors.New(strings.Join(errs, "\n")) return errors.New(strings.Join(errs, "\n"))