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

Commit 66fb790

Browse files
authored
Merge pull request #1246 from ulyssessouza/label-envfiles
Add environment_files label on service's `env_file` section
2 parents ff5e3a5 + dc80f6b commit 66fb790

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
@@ -21,8 +21,9 @@ import (
2121
"strconv"
2222
"strings"
2323

24-
"github.com/docker/compose-cli/api/compose"
2524
"github.com/docker/docker/api/types/filters"
25+
26+
"github.com/docker/compose-cli/api/compose"
2627
)
2728

2829
const (
@@ -38,7 +39,7 @@ const (
3839
configHashLabel = "com.docker.compose.config-hash"
3940
networkLabel = compose.NetworkTag
4041

41-
//ComposeVersion Compose version
42+
// ComposeVersion Compose version
4243
ComposeVersion = "1.0-alpha"
4344
)
4445

0 commit comments

Comments
 (0)