feat: final round of hacks for deploy command

This commit is contained in:
decentral1se 2021-09-03 11:46:40 +02:00
parent 92c8e9aab9
commit 612fc5a531
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 40 additions and 0 deletions

View File

@ -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(),

View File

@ -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
}