fix: respect COMPOSE_FILE when loading compose files

Final part of coop-cloud/go-abra#57.
This commit is contained in:
2021-09-04 22:02:49 +02:00
parent a8f30426ea
commit e68c7fc71c
4 changed files with 38 additions and 23 deletions

View File

@ -225,22 +225,35 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) {
return statuses, nil
}
// GetAppComposeFiles retrieves a compose specification for a recipe. This
// specification is the result of a merge of all the compose.**.yml files in
// the recipe repository.
func GetAppComposeFiles(recipe string, appEnv AppEnv) (*composetypes.Config, error) {
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
return &composetypes.Config{}, err
// GetAppComposeFiles gets the list of compose files for an app which should be
// merged into a composetypes.Config while respecting the COMPOSE_FILE env var.
func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) {
if _, ok := appEnv["COMPOSE_FILE"]; !ok {
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
return composeFiles, err
}
return composeFiles, nil
}
opts := stack.Deploy{Composefiles: composeFiles}
var composeFiles []string
composeFileEnvVar := appEnv["COMPOSE_FILE"]
for _, file := range strings.Split(composeFileEnvVar, ":") {
path := fmt.Sprintf("%s/%s/%s", APPS_DIR, recipe, file)
composeFiles = append(composeFiles, path)
}
return composeFiles, nil
}
// GetAppComposeConfig retrieves a compose specification for a recipe. This
// specification is the result of a merge of all the compose.**.yml files in
// the recipe repository.
func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv AppEnv) (*composetypes.Config, error) {
compose, err := loader.LoadComposefile(opts, appEnv)
if err != nil {
return &composetypes.Config{}, err
}
return compose, nil
}