From dc80f6b6e7176f36c31d7a6d8185e86d36459bf0 Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Thu, 4 Feb 2021 18:52:16 -0300 Subject: [PATCH] Add environment_files label Signed-off-by: Ulysses Souza --- api/compose/tags.go | 2 ++ cli/cmd/compose/up.go | 18 ++++++++++++++++++ local/compose/labels.go | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/api/compose/tags.go b/api/compose/tags.go index 042a1409b..b790e570c 100644 --- a/api/compose/tags.go +++ b/api/compose/tags.go @@ -25,4 +25,6 @@ const ( ServiceTag = "com.docker.compose.service" // VolumeTag allow to track resource related to a compose volume VolumeTag = "com.docker.compose.volume" + // EnvironmentFileLabel is set in containers with the option "--env-file" when set + EnvironmentFileLabel = "com.docker.compose.project.environment_file" ) diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index 358860d63..90da72c0c 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -21,6 +21,7 @@ import ( "errors" "fmt" "os" + "path/filepath" "github.com/docker/compose-cli/api/client" "github.com/docker/compose-cli/api/compose" @@ -175,6 +176,23 @@ func setup(ctx context.Context, opts composeOptions, services []string) (*client service.PullPolicy = types.PullPolicyBuild } } + if opts.EnvFile != "" { + var services types.Services + for _, s := range project.Services { + ef := opts.EnvFile + if ef != "" { + if !filepath.IsAbs(ef) { + ef = filepath.Join(project.WorkingDir, opts.EnvFile) + } + if s.Labels == nil { + s.Labels = make(map[string]string) + } + s.Labels[compose.EnvironmentFileLabel] = ef + services = append(services, s) + } + } + project.Services = services + } return c, project, nil } diff --git a/local/compose/labels.go b/local/compose/labels.go index f506a70a8..c658c1df7 100644 --- a/local/compose/labels.go +++ b/local/compose/labels.go @@ -19,8 +19,9 @@ package compose import ( "fmt" - "github.com/docker/compose-cli/api/compose" "github.com/docker/docker/api/types/filters" + + "github.com/docker/compose-cli/api/compose" ) const ( @@ -36,7 +37,7 @@ const ( configHashLabel = "com.docker.compose.config-hash" networkLabel = compose.NetworkTag - //ComposeVersion Compose version + // ComposeVersion Compose version ComposeVersion = "1.0-alpha" )