WIP heinous appEnv threading for env var loading

This commit is contained in:
decentral1se 2021-09-01 15:01:20 +02:00
parent 09873b42ce
commit 063fa66af9
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
5 changed files with 47 additions and 18 deletions

View File

@ -51,7 +51,7 @@ var appDeployCommand = &cli.Command{
Prune: false,
ResolveImage: stack.ResolveImageAlways,
}
compose, err := loader.LoadComposefile(deployOpts)
compose, err := loader.LoadComposefile(deployOpts, appEnv.Env)
if err != nil {
logrus.Fatal(err)
}

View File

@ -61,7 +61,7 @@ var appVersionCommand = &cli.Command{
app := appFiles[appName]
compose, err := config.GetAppComposeFiles(appEnv.Type)
compose, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env)
if err != nil {
logrus.Fatal(err)
}

View File

@ -172,7 +172,17 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
compose, err := config.GetAppComposeFiles(recipe)
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
appEnv, err := config.GetApp(appFiles, recipe)
if err != nil {
logrus.Fatal(err)
}
compose, err := config.GetAppComposeFiles(recipe, appEnv.Env)
if err != nil {
logrus.Fatal(err)
}
@ -263,7 +273,7 @@ This is step 1 of upgrading a recipe. Step 2 is running "abra recipe sync
logrus.Fatal(err)
}
if err := config.UpdateAppComposeTag(recipe, image, upgradeTag); err != nil {
if err := config.UpdateAppComposeTag(recipe, image, upgradeTag, appEnv.Env); err != nil {
logrus.Fatal(err)
}
}
@ -292,7 +302,17 @@ the versioning metadata of up-and-running containers are.
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
compose, err := config.GetAppComposeFiles(recipe)
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
appEnv, err := config.GetApp(appFiles, recipe)
if err != nil {
logrus.Fatal(err)
}
compose, err := config.GetAppComposeFiles(recipe, appEnv.Env)
if err != nil {
logrus.Fatal(err)
}
@ -321,7 +341,7 @@ the versioning metadata of up-and-running containers are.
tag := img.(reference.NamedTagged).Tag()
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s-%s", service.Name, tag, digest)
if err := config.UpdateAppComposeLabel(recipe, service.Name, label); err != nil {
if err := config.UpdateAppComposeLabel(recipe, service.Name, label, appEnv.Env); err != nil {
logrus.Fatal(err)
}
}
@ -340,7 +360,17 @@ var recipeLintCommand = &cli.Command{
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
compose, err := config.GetAppComposeFiles(recipe)
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
appEnv, err := config.GetApp(appFiles, recipe)
if err != nil {
logrus.Fatal(err)
}
compose, err := config.GetAppComposeFiles(recipe, appEnv.Env)
if err != nil {
logrus.Fatal(err)
}

View File

@ -3,7 +3,6 @@ package stack
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
@ -16,8 +15,8 @@ import (
)
// LoadComposefile parse the composefile specified in the cli and returns its Config and version.
func LoadComposefile(opts options.Deploy) (*composetypes.Config, error) {
configDetails, err := getConfigDetails(opts.Composefiles)
func LoadComposefile(opts options.Deploy, appEnv map[string]string) (*composetypes.Config, error) {
configDetails, err := getConfigDetails(opts.Composefiles, appEnv)
if err != nil {
return nil, err
}
@ -66,7 +65,7 @@ func propertyWarnings(properties map[string]string) string {
return strings.Join(msgs, "\n\n")
}
func getConfigDetails(composefiles []string) (composetypes.ConfigDetails, error) {
func getConfigDetails(composefiles []string, appEnv map[string]string) (composetypes.ConfigDetails, error) {
var details composetypes.ConfigDetails
absPath, err := filepath.Abs(composefiles[0])
@ -81,7 +80,7 @@ func getConfigDetails(composefiles []string) (composetypes.ConfigDetails, error)
}
// Take the first file version (2 files can't have different version)
details.Version = schema.Version(details.ConfigFiles[0].Config)
details.Environment, err = buildEnvironment(os.Environ())
details.Environment = appEnv
return details, err
}

View File

@ -229,7 +229,7 @@ func GetAppStatuses(appFiles AppFiles) (map[string]string, error) {
// 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) (*composetypes.Config, error) {
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 {
@ -237,7 +237,7 @@ func GetAppComposeFiles(recipe string) (*composetypes.Config, error) {
}
opts := options.Deploy{Composefiles: composeFiles}
compose, err := loader.LoadComposefile(opts)
compose, err := loader.LoadComposefile(opts, appEnv)
if err != nil {
return &composetypes.Config{}, err
}
@ -245,7 +245,7 @@ func GetAppComposeFiles(recipe string) (*composetypes.Config, error) {
return compose, nil
}
func UpdateAppComposeTag(recipe, image, tag string) error {
func UpdateAppComposeTag(recipe, image, tag string, appEnv AppEnv) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
@ -254,7 +254,7 @@ func UpdateAppComposeTag(recipe, image, tag string) error {
for _, composeFile := range composeFiles {
opts := options.Deploy{Composefiles: []string{composeFile}}
compose, err := loader.LoadComposefile(opts)
compose, err := loader.LoadComposefile(opts, appEnv)
if err != nil {
return err
}
@ -298,7 +298,7 @@ func UpdateAppComposeTag(recipe, image, tag string) error {
return nil
}
func UpdateAppComposeLabel(recipe, serviceName, newLabel string) error {
func UpdateAppComposeLabel(recipe, serviceName, newLabel string, appEnv AppEnv) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
@ -307,7 +307,7 @@ func UpdateAppComposeLabel(recipe, serviceName, newLabel string) error {
for _, composeFile := range composeFiles {
opts := options.Deploy{Composefiles: []string{composeFile}}
compose, err := loader.LoadComposefile(opts)
compose, err := loader.LoadComposefile(opts, appEnv)
if err != nil {
return err
}