From c648e0b065e70709fff539770a1e5f3349ebcb6b 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 (cherry picked from commit ff7f76af7a092ca9aeb689850d4ad0a85746bc72) 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 b4fc151474..2a61d5e48c 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -164,8 +164,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")