diff --git a/cli/app/deploy.go b/cli/app/deploy.go index 323c773a4..7dc2c1f2c 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -3,11 +3,9 @@ package app import ( "errors" "fmt" - "path/filepath" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/client" - loader "coopcloud.tech/abra/client/stack" stack "coopcloud.tech/abra/client/stack" "coopcloud.tech/abra/config" "github.com/sirupsen/logrus" @@ -39,12 +37,6 @@ var appDeployCommand = &cli.Command{ logrus.Fatal(err) } - pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, appEnv.Type) - composeFiles, err := filepath.Glob(pattern) - if err != nil { - logrus.Fatal(err) - } - abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, appEnv.Type, "abra.sh") abraShEnv, err := config.ReadAbraShEnvVars(abraShPath) if err != nil { @@ -55,13 +47,17 @@ var appDeployCommand = &cli.Command{ } appEnv.Env["STACK_NAME"] = appEnv.StackName() + composeFiles, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env) + if err != nil { + logrus.Fatal(err) + } deployOpts := stack.Deploy{ Composefiles: composeFiles, Namespace: appEnv.StackName(), Prune: false, ResolveImage: stack.ResolveImageAlways, } - compose, err := loader.LoadComposefile(deployOpts, appEnv.Env) + compose, err := config.GetAppComposeConfig(appName, deployOpts, appEnv.Env) if err != nil { logrus.Fatal(err) } diff --git a/cli/app/version.go b/cli/app/version.go index ea85a87d4..f644b1d18 100644 --- a/cli/app/version.go +++ b/cli/app/version.go @@ -61,7 +61,12 @@ var appVersionCommand = &cli.Command{ app := appFiles[appName] - compose, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env) + composeFiles, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env) + if err != nil { + logrus.Fatal(err) + } + opts := stack.Deploy{Composefiles: composeFiles} + compose, err := config.GetAppComposeConfig(appEnv.Type, opts, appEnv.Env) if err != nil { logrus.Fatal(err) } diff --git a/cli/recipe/recipe.go b/cli/recipe/recipe.go index ab23caa54..aed75c389 100644 --- a/cli/recipe/recipe.go +++ b/cli/recipe/recipe.go @@ -14,6 +14,7 @@ import ( "coopcloud.tech/abra/cli/formatter" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/client" + "coopcloud.tech/abra/client/stack" "coopcloud.tech/abra/config" "coopcloud.tech/tagcmp" @@ -182,7 +183,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync logrus.Fatal(err) } - compose, err := config.GetAppComposeFiles(recipe, appEnv.Env) + compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env) if err != nil { logrus.Fatal(err) } @@ -312,7 +313,7 @@ the versioning metadata of up-and-running containers are. logrus.Fatal(err) } - compose, err := config.GetAppComposeFiles(recipe, appEnv.Env) + compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env) if err != nil { logrus.Fatal(err) } @@ -370,7 +371,7 @@ var recipeLintCommand = &cli.Command{ logrus.Fatal(err) } - compose, err := config.GetAppComposeFiles(recipe, appEnv.Env) + compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env) if err != nil { logrus.Fatal(err) } diff --git a/config/app.go b/config/app.go index 599bc9fbd..6b7b3948f 100644 --- a/config/app.go +++ b/config/app.go @@ -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 }