fix: respect COMPOSE_FILE when loading compose files
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Final part of coop-cloud/go-abra#57.
This commit is contained in:
parent
a8f30426ea
commit
e68c7fc71c
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue