fix(path): fixing the default compose file check
All checks were successful
Go-Tests / tests (pull_request) Successful in 1m54s
Go-Tests / sonar (pull_request) Successful in 1m15s

This commit is contained in:
2026-03-15 21:50:26 +01:00
parent 5d839035b9
commit 0e133ae6db
2 changed files with 23 additions and 7 deletions

View File

@@ -109,8 +109,19 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
// the current working directory is the directory
currentDir, _ := os.Getwd()
// Filter to only existing files before chdir
var existingFiles []string
for _, f := range dockerComposeFile {
if _, err := os.Stat(f); err == nil {
existingFiles = append(existingFiles, f)
}
}
if len(existingFiles) == 0 && len(dockerComposeFile) > 0 {
return fmt.Errorf("no compose file found: %v", dockerComposeFile)
}
// go to the root of the project
if err := os.Chdir(filepath.Dir(dockerComposeFile[0])); err != nil {
if err := os.Chdir(filepath.Dir(existingFiles[0])); err != nil {
logger.Failure(err.Error())
return err
}
@@ -122,12 +133,12 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
}()
// repove the directory part of the docker-compose files
for i, f := range dockerComposeFile {
dockerComposeFile[i] = filepath.Base(f)
for i, f := range existingFiles {
existingFiles[i] = filepath.Base(f)
}
// parse the compose files
project, err := parser.Parse(config.Profiles, config.EnvFiles, dockerComposeFile...)
project, err := parser.Parse(config.Profiles, config.EnvFiles, existingFiles...)
if err != nil {
logger.Failure("Cannot parse compose files", err.Error())
return err