From f2e7680bf389e1cb83d1031c55e690d5dc591647 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Tue, 26 Nov 2024 22:09:58 -0300 Subject: [PATCH] fix(compose): fix path resolution for env files BE-11428 (#167) --- pkg/libstack/compose/composeplugin.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/libstack/compose/composeplugin.go b/pkg/libstack/compose/composeplugin.go index c2a086092..33d5a83ae 100644 --- a/pkg/libstack/compose/composeplugin.go +++ b/pkg/libstack/compose/composeplugin.go @@ -70,20 +70,18 @@ func withComposeService( return withCli(ctx, options, func(ctx context.Context, cli *command.DockerCli) error { composeService := compose.NewComposeService(cli) - configDetails := types.ConfigDetails{ - WorkingDir: options.WorkingDir, - } - - for _, p := range filePaths { - configDetails.ConfigFiles = append(configDetails.ConfigFiles, types.ConfigFile{Filename: p}) - } - env, err := parseEnvironment(options) if err != nil { return err } - configDetails.Environment = env + configDetails := types.ConfigDetails{ + Environment: env, + } + + for _, p := range filePaths { + configDetails.ConfigFiles = append(configDetails.ConfigFiles, types.ConfigFile{Filename: p}) + } if len(configDetails.ConfigFiles) == 0 { return composeFn(composeService, nil) @@ -107,7 +105,7 @@ func withComposeService( for i, service := range project.Services { for j, envFile := range service.EnvFiles { if !filepath.IsAbs(envFile.Path) { - project.Services[i].EnvFiles[j].Path = filepath.Join(project.WorkingDir, envFile.Path) + project.Services[i].EnvFiles[j].Path = filepath.Join(filepath.Dir(filePaths[0]), envFile.Path) } } }