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 // the current working directory is the directory
currentDir, _ := os.Getwd() 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 // 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()) logger.Failure(err.Error())
return err return err
} }
@@ -122,12 +133,12 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
}() }()
// repove the directory part of the docker-compose files // repove the directory part of the docker-compose files
for i, f := range dockerComposeFile { for i, f := range existingFiles {
dockerComposeFile[i] = filepath.Base(f) existingFiles[i] = filepath.Base(f)
} }
// parse the compose files // 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 { if err != nil {
logger.Failure("Cannot parse compose files", err.Error()) logger.Failure("Cannot parse compose files", err.Error())
return err return err

View File

@@ -41,16 +41,21 @@ func Parse(profiles []string, envFiles []string, dockerComposeFile ...string) (*
} }
} }
options, err := cli.NewProjectOptions(dockerComposeFile, opts := []cli.ProjectOptionsFn{
cli.WithProfiles(profiles), cli.WithProfiles(profiles),
cli.WithInterpolation(true), cli.WithInterpolation(true),
cli.WithDefaultConfigPath,
cli.WithEnvFiles(envFiles...), cli.WithEnvFiles(envFiles...),
cli.WithOsEnv, cli.WithOsEnv,
cli.WithDotEnv, cli.WithDotEnv,
cli.WithNormalization(true), cli.WithNormalization(true),
cli.WithResolvedPaths(false), cli.WithResolvedPaths(false),
) }
if len(dockerComposeFile) == 0 {
opts = append(opts, cli.WithDefaultConfigPath)
}
options, err := cli.NewProjectOptions(dockerComposeFile, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }