Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit dc80f6b

Browse files
committed
Add environment_files label
Signed-off-by: Ulysses Souza <[email protected]>
1 parent caec924 commit dc80f6b

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

api/compose/tags.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ const (
2525
ServiceTag = "com.docker.compose.service"
2626
// VolumeTag allow to track resource related to a compose volume
2727
VolumeTag = "com.docker.compose.volume"
28+
// EnvironmentFileLabel is set in containers with the option "--env-file" when set
29+
EnvironmentFileLabel = "com.docker.compose.project.environment_file"
2830
)

cli/cmd/compose/up.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"errors"
2222
"fmt"
2323
"os"
24+
"path/filepath"
2425

2526
"github.com/docker/compose-cli/api/client"
2627
"github.com/docker/compose-cli/api/compose"
@@ -175,6 +176,23 @@ func setup(ctx context.Context, opts composeOptions, services []string) (*client
175176
service.PullPolicy = types.PullPolicyBuild
176177
}
177178
}
179+
if opts.EnvFile != "" {
180+
var services types.Services
181+
for _, s := range project.Services {
182+
ef := opts.EnvFile
183+
if ef != "" {
184+
if !filepath.IsAbs(ef) {
185+
ef = filepath.Join(project.WorkingDir, opts.EnvFile)
186+
}
187+
if s.Labels == nil {
188+
s.Labels = make(map[string]string)
189+
}
190+
s.Labels[compose.EnvironmentFileLabel] = ef
191+
services = append(services, s)
192+
}
193+
}
194+
project.Services = services
195+
}
178196

179197
return c, project, nil
180198
}

local/compose/labels.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package compose
1919
import (
2020
"fmt"
2121

22-
"github.com/docker/compose-cli/api/compose"
2322
"github.com/docker/docker/api/types/filters"
23+
24+
"github.com/docker/compose-cli/api/compose"
2425
)
2526

2627
const (
@@ -36,7 +37,7 @@ const (
3637
configHashLabel = "com.docker.compose.config-hash"
3738
networkLabel = compose.NetworkTag
3839

39-
//ComposeVersion Compose version
40+
// ComposeVersion Compose version
4041
ComposeVersion = "1.0-alpha"
4142
)
4243

0 commit comments

Comments
 (0)