diff --git a/cli/app/deploy.go b/cli/app/deploy.go index 58ae72009..ab73a8890 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -46,6 +46,16 @@ var appDeployCommand = &cli.Command{ logrus.Fatal(err) } + abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, appEnv.Type, "abra.sh") + abraShEnv, err := config.ReadAbraShEnvVars(abraShPath) + if err != nil { + logrus.Fatal(err) + } + for k, v := range abraShEnv { + appEnv.Env[k] = v + } + appEnv.Env["STACK_NAME"] = appEnv.StackName() + deployOpts := options.Deploy{ Composefiles: composeFiles, Namespace: appEnv.StackName(), diff --git a/config/env.go b/config/env.go index 487ea3456..4e4009291 100644 --- a/config/env.go +++ b/config/env.go @@ -1,12 +1,14 @@ package config import ( + "bufio" "fmt" "io/fs" "io/ioutil" "os" "path" "path/filepath" + "strings" "github.com/Autonomic-Cooperative/godotenv" "github.com/sirupsen/logrus" @@ -109,3 +111,31 @@ func EnsureAbraDirExists() error { } return nil } + +func ReadAbraShEnvVars(abraSh string) (map[string]string, error) { + envVars := make(map[string]string) + + file, err := os.Open(abraSh) + if err != nil { + if os.IsNotExist(err) { + return envVars, fmt.Errorf("'%s' does not exist?", abraSh) + } + return envVars, err + } + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + if strings.Contains(line, "export") { + splitVals := strings.Split(line, "export ") + envVarDef := splitVals[len(splitVals)-1] + keyVal := strings.Split(envVarDef, "=") + if len(keyVal) != 2 { + return envVars, fmt.Errorf("couldn't parse %s", line) + } + envVars[keyVal[0]] = keyVal[1] + } + } + + return envVars, nil +}