fix: respect COMPOSE_FILE when loading compose files
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Final part of coop-cloud/go-abra#57.
This commit is contained in:
parent
a8f30426ea
commit
e68c7fc71c
@ -3,11 +3,9 @@ package app
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/client"
|
"coopcloud.tech/abra/client"
|
||||||
loader "coopcloud.tech/abra/client/stack"
|
|
||||||
stack "coopcloud.tech/abra/client/stack"
|
stack "coopcloud.tech/abra/client/stack"
|
||||||
"coopcloud.tech/abra/config"
|
"coopcloud.tech/abra/config"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -39,12 +37,6 @@ var appDeployCommand = &cli.Command{
|
|||||||
logrus.Fatal(err)
|
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")
|
abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, appEnv.Type, "abra.sh")
|
||||||
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
|
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -55,13 +47,17 @@ var appDeployCommand = &cli.Command{
|
|||||||
}
|
}
|
||||||
appEnv.Env["STACK_NAME"] = appEnv.StackName()
|
appEnv.Env["STACK_NAME"] = appEnv.StackName()
|
||||||
|
|
||||||
|
composeFiles, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
deployOpts := stack.Deploy{
|
deployOpts := stack.Deploy{
|
||||||
Composefiles: composeFiles,
|
Composefiles: composeFiles,
|
||||||
Namespace: appEnv.StackName(),
|
Namespace: appEnv.StackName(),
|
||||||
Prune: false,
|
Prune: false,
|
||||||
ResolveImage: stack.ResolveImageAlways,
|
ResolveImage: stack.ResolveImageAlways,
|
||||||
}
|
}
|
||||||
compose, err := loader.LoadComposefile(deployOpts, appEnv.Env)
|
compose, err := config.GetAppComposeConfig(appName, deployOpts, appEnv.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,12 @@ var appVersionCommand = &cli.Command{
|
|||||||
|
|
||||||
app := appFiles[appName]
|
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 {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"coopcloud.tech/abra/cli/formatter"
|
"coopcloud.tech/abra/cli/formatter"
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/client"
|
"coopcloud.tech/abra/client"
|
||||||
|
"coopcloud.tech/abra/client/stack"
|
||||||
"coopcloud.tech/abra/config"
|
"coopcloud.tech/abra/config"
|
||||||
"coopcloud.tech/tagcmp"
|
"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)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
compose, err := config.GetAppComposeFiles(recipe, appEnv.Env)
|
compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -312,7 +313,7 @@ the versioning metadata of up-and-running containers are.
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
compose, err := config.GetAppComposeFiles(recipe, appEnv.Env)
|
compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -370,7 +371,7 @@ var recipeLintCommand = &cli.Command{
|
|||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
compose, err := config.GetAppComposeFiles(recipe, appEnv.Env)
|
compose, err := config.GetAppComposeConfig(recipe, stack.Deploy{}, appEnv.Env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -225,22 +225,35 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) {
|
|||||||
return statuses, nil
|
return statuses, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAppComposeFiles retrieves a compose specification for a recipe. This
|
// GetAppComposeFiles gets the list of compose files for an app which should be
|
||||||
// specification is the result of a merge of all the compose.**.yml files in
|
// merged into a composetypes.Config while respecting the COMPOSE_FILE env var.
|
||||||
// the recipe repository.
|
func GetAppComposeFiles(recipe string, appEnv AppEnv) ([]string, error) {
|
||||||
func GetAppComposeFiles(recipe string, appEnv AppEnv) (*composetypes.Config, error) {
|
if _, ok := appEnv["COMPOSE_FILE"]; !ok {
|
||||||
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
|
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
|
||||||
composeFiles, err := filepath.Glob(pattern)
|
composeFiles, err := filepath.Glob(pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &composetypes.Config{}, err
|
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)
|
compose, err := loader.LoadComposefile(opts, appEnv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &composetypes.Config{}, err
|
return &composetypes.Config{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return compose, nil
|
return compose, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user