Skip to content

Commit 01c47eb

Browse files
fix(compose): correctly handle multiple compose files with -f/--file option
Previously, the logic only processed the first file when multiple compose files were passed with the -f/--file option, ignoring the others. This fix ensures that all specified compose files are correctly processed during auto-extraction. Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
1 parent 326a66e commit 01c47eb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

cmd/werf/compose/main.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (d *composeCmdData) GetOrExtractImagesToProcess(werfConfig *config.WerfConf
6565
return s
6666
}
6767

68-
extractedImageNameList, err := extractImageNamesFromComposeConfig(d.getComposeFilePath())
68+
extractedImageNameList, err := extractImageNamesFromComposeConfig(d.getComposeFileCustomPathList())
6969
if err != nil {
7070
return build.ImagesToProcess{}, fmt.Errorf("unable to extract image names from docker-compose file: %w", err)
7171
}
@@ -90,23 +90,28 @@ func (d *composeCmdData) GetOrExtractImagesToProcess(werfConfig *config.WerfConf
9090
return build.NewImagesToProcess(imageNameList, len(imageNameList) == 0), nil
9191
}
9292

93-
func (d *composeCmdData) getComposeFilePath() string {
93+
func (d *composeCmdData) getComposeFileCustomPathList() []string {
94+
var result []string
9495
for ind, value := range d.ComposeOptions {
9596
if strings.HasPrefix(value, "-f") || strings.HasPrefix(value, "--file") {
9697
parts := strings.Split(value, "=")
9798
if len(parts) == 2 {
98-
return parts[1]
99+
result = append(result, parts[1])
99100
} else if len(d.ComposeOptions) > ind+1 {
100-
return d.ComposeOptions[ind+1]
101+
result = append(result, d.ComposeOptions[ind+1])
101102
}
102103
}
103104
}
104105

105-
return "docker-compose.yml"
106+
return result
106107
}
107108

108-
func extractImageNamesFromComposeConfig(filename string) ([]string, error) {
109-
composeArgs := []string{"compose", "--file", filename, "config", "--no-interpolate"}
109+
func extractImageNamesFromComposeConfig(customConfigPathList []string) ([]string, error) {
110+
composeArgs := []string{"compose"}
111+
for _, p := range customConfigPathList {
112+
composeArgs = append(composeArgs, "--file", p)
113+
}
114+
composeArgs = append(composeArgs, "config", "--no-interpolate")
110115

111116
cmd := exec.Command("docker", composeArgs...)
112117
var stdout, stderr bytes.Buffer

0 commit comments

Comments
 (0)