From ff7f76af7a092ca9aeb689850d4ad0a85746bc72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 19 Apr 2023 14:06:01 +0200 Subject: [PATCH] Handle empty DOCKER_BUILDKIT like unset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the cli erroring out if the variable is set to an empty value. ``` $ export DOCKER_BUILDKIT= $ docker version DOCKER_BUILDKIT environment variable expects boolean value: strconv.ParseBool: parsing "": invalid syntax ``` Signed-off-by: Paweł Gronowski --- cli/command/cli.go | 4 ++-- cmd/docker/builder.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/command/cli.go b/cli/command/cli.go index 0306f242d3..4d8b9dc406 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -162,8 +162,8 @@ func (cli *DockerCli) ContentTrustEnabled() bool { // BuildKitEnabled returns buildkit is enabled or not. func (cli *DockerCli) BuildKitEnabled() (bool, error) { - // use DOCKER_BUILDKIT env var value if set - if v, ok := os.LookupEnv("DOCKER_BUILDKIT"); ok { + // use DOCKER_BUILDKIT env var value if set and not empty + if v := os.Getenv("DOCKER_BUILDKIT"); v != "" { enabled, err := strconv.ParseBool(v) if err != nil { return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value") diff --git a/cmd/docker/builder.go b/cmd/docker/builder.go index 71fe979b38..7807f80b1a 100644 --- a/cmd/docker/builder.go +++ b/cmd/docker/builder.go @@ -44,9 +44,9 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st var buildKitDisabled, useBuilder, useAlias bool var envs []string - // check DOCKER_BUILDKIT env var is present and - // if not assume we want to use the builder component - if v, ok := os.LookupEnv("DOCKER_BUILDKIT"); ok { + // check DOCKER_BUILDKIT env var is not empty + // if it is assume we want to use the builder component + if v := os.Getenv("DOCKER_BUILDKIT"); v != "" { enabled, err := strconv.ParseBool(v) if err != nil { return args, osargs, nil, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")