Skip to content

Commit d4a4dcf

Browse files
committed
resolve --env-file as absolute path
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 05e987d commit d4a4dcf

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

cmd/compose/compose.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,6 @@ func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn
187187
return nil, compose.WrapComposeError(err)
188188
}
189189

190-
ef := o.EnvFile
191-
if ef != "" && !filepath.IsAbs(ef) {
192-
ef, err = filepath.Abs(ef)
193-
if err != nil {
194-
return nil, err
195-
}
196-
}
197190
for i, s := range project.Services {
198191
s.CustomLabels = map[string]string{
199192
api.ProjectLabel: project.Name,
@@ -203,8 +196,8 @@ func (o *projectOptions) toProject(services []string, po ...cli.ProjectOptionsFn
203196
api.ConfigFilesLabel: strings.Join(project.ComposeFiles, ","),
204197
api.OneoffLabel: "False", // default, will be overridden by `run` command
205198
}
206-
if ef != "" {
207-
s.CustomLabels[api.EnvironmentFileLabel] = ef
199+
if o.EnvFile != "" {
200+
s.CustomLabels[api.EnvironmentFileLabel] = o.EnvFile
208201
}
209202
project.Services[i] = s
210203
}
@@ -250,7 +243,7 @@ func RunningAsStandalone() bool {
250243
}
251244

252245
// RootCommand returns the compose command with its child commands
253-
func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command {
246+
func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command { //nolint:gocyclo
254247
// filter out useless commandConn.CloseWrite warning message that can occur
255248
// when using a remote context that is unreachable: "commandConn.CloseWrite: commandconn: failed to wait: signal: killed"
256249
// https://github.com/docker/cli/blob/e1f24d3c93df6752d3c27c8d61d18260f141310c/cli/connhelper/commandconn/commandconn.go#L203-L215
@@ -326,6 +319,12 @@ func RootCommand(dockerCli command.Cli, backend api.Service) *cobra.Command {
326319
opts.ProjectDir = opts.WorkDir
327320
fmt.Fprint(os.Stderr, aec.Apply("option '--workdir' is DEPRECATED at root level! Please use '--project-directory' instead.\n", aec.RedF))
328321
}
322+
if opts.EnvFile != "" && !filepath.IsAbs(opts.EnvFile) {
323+
opts.EnvFile, err = filepath.Abs(opts.EnvFile)
324+
if err != nil {
325+
return err
326+
}
327+
}
329328
if parallel > 0 {
330329
backend.MaxConcurrency(parallel)
331330
}

0 commit comments

Comments
 (0)