fix(path): fixing the default compose file check
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user