From 662c0768cb9ed0f6ef19f43fa8c12defbafbf07a Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Tue, 30 Jul 2019 16:44:05 -0700 Subject: [PATCH] bake: replace env in compose files Signed-off-by: Tonis Tiigi --- bake/compose.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/bake/compose.go b/bake/compose.go index eac95bf3..558052aa 100644 --- a/bake/compose.go +++ b/bake/compose.go @@ -2,7 +2,9 @@ package bake import ( "fmt" + "os" "reflect" + "strings" "github.com/docker/cli/cli/compose/loader" composetypes "github.com/docker/cli/cli/compose/types" @@ -19,9 +21,22 @@ func parseCompose(dt []byte) (*composetypes.Config, error) { Config: parsed, }, }, + Environment: envMap(os.Environ()), }) } +func envMap(env []string) map[string]string { + result := make(map[string]string, len(env)) + for _, s := range env { + kv := strings.SplitN(s, "=", 2) + if len(kv) != 2 { + continue + } + result[kv[0]] = kv[1] + } + return result +} + func ParseCompose(dt []byte) (*Config, error) { cfg, err := parseCompose(dt) if err != nil {