Skip to content

Commit

Permalink
fix(compose): correctly handle multiple compose files with -f/--file …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
alexey-igrychev committed Aug 28, 2024
1 parent 326a66e commit 01c47eb
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions cmd/werf/compose/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (d *composeCmdData) GetOrExtractImagesToProcess(werfConfig *config.WerfConf
return s
}

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

func (d *composeCmdData) getComposeFilePath() string {
func (d *composeCmdData) getComposeFileCustomPathList() []string {
var result []string
for ind, value := range d.ComposeOptions {
if strings.HasPrefix(value, "-f") || strings.HasPrefix(value, "--file") {
parts := strings.Split(value, "=")
if len(parts) == 2 {
return parts[1]
result = append(result, parts[1])
} else if len(d.ComposeOptions) > ind+1 {
return d.ComposeOptions[ind+1]
result = append(result, d.ComposeOptions[ind+1])
}
}
}

return "docker-compose.yml"
return result
}

func extractImageNamesFromComposeConfig(filename string) ([]string, error) {
composeArgs := []string{"compose", "--file", filename, "config", "--no-interpolate"}
func extractImageNamesFromComposeConfig(customConfigPathList []string) ([]string, error) {
composeArgs := []string{"compose"}
for _, p := range customConfigPathList {
composeArgs = append(composeArgs, "--file", p)
}
composeArgs = append(composeArgs, "config", "--no-interpolate")

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

0 comments on commit 01c47eb

Please sign in to comment.