diff --git a/bake/compose.go b/bake/compose.go index eac95bf3..7bc759ed 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -2,6 +2,7 @@ package bake import ( "fmt" + "os" "reflect" "github.com/docker/cli/cli/compose/loader" @@ -86,6 +87,8 @@ func toMap(in composetypes.MappingWithEquals) map[string]string { for k, v := range in { if v != nil { m[k] = *v + } else { + m[k] = os.Getenv(k) } } return m diff --git a/commands/build.go b/commands/build.go index 1e583293..62dc5847 100644 --- a/commands/build.go +++ b/commands/build.go @@ -84,8 +84,8 @@ func runBuild(dockerCli command.Cli, in buildOptions) error { InStream: os.Stdin, }, Tags: in.tags, - Labels: listToMap(in.labels), - BuildArgs: listToMap(in.buildArgs), + Labels: listToMap(in.labels, false), + BuildArgs: listToMap(in.buildArgs, true), Pull: in.pull, NoCache: in.noCache, Target: in.target, @@ -282,12 +282,16 @@ func commonFlags(options *commonOptions, flags *pflag.FlagSet) { flags.BoolVar(&options.pull, "pull", false, "Always attempt to pull a newer version of the image") } -func listToMap(values []string) map[string]string { +func listToMap(values []string, defaultEnv bool) map[string]string { result := make(map[string]string, len(values)) for _, value := range values { kv := strings.SplitN(value, "=", 2) if len(kv) == 1 { - result[kv[0]] = "" + if defaultEnv { + result[kv[0]] = os.Getenv(kv[0]) + } else { + result[kv[0]] = "" + } } else { result[kv[0]] = kv[1] }