66 lines
1.3 KiB
Go
66 lines
1.3 KiB
Go
package app
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/config"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var appCheckCommand = &cli.Command{
|
|
Name: "check",
|
|
ArgsUsage: "<service>",
|
|
Action: func(c *cli.Context) error {
|
|
appName := c.Args().First()
|
|
if appName == "" {
|
|
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided"))
|
|
}
|
|
|
|
appFiles, err := config.LoadAppFiles("")
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
appEnv, err := config.GetApp(appFiles, appName)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
envSamplePath := path.Join(config.ABRA_DIR, "apps", appEnv.Type, ".env.sample")
|
|
if _, err := os.Stat(envSamplePath); err != nil {
|
|
if os.IsNotExist(err) {
|
|
logrus.Fatalf("'%s' does not exist?", envSamplePath)
|
|
}
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
envSample, err := config.ReadEnv(envSamplePath)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
var missing []string
|
|
for k, _ := range envSample {
|
|
if _, ok := appEnv.Env[k]; !ok {
|
|
missing = append(missing, k)
|
|
}
|
|
}
|
|
|
|
if len(missing) > 0 {
|
|
path := appFiles[appName].Path
|
|
missingEnvVars := fmt.Sprintf(strings.Join(missing, ", "))
|
|
logrus.Fatalf("%s is missing %s", path, missingEnvVars)
|
|
}
|
|
|
|
logrus.Info("All necessary environment variables defined")
|
|
|
|
return nil
|
|
},
|
|
}
|