forked from coop-cloud/abra
feat: implement check command
This commit is contained in:
parent
23737ed3a7
commit
8ad51c1fd5
2
TODO.md
2
TODO.md
@ -16,7 +16,7 @@
|
||||
- [x] `new`
|
||||
- [x] `backup`
|
||||
- [ ] `deploy` (WIP: decentral1se)
|
||||
- [ ] `check` (WIP: decentral1se)
|
||||
- [x] `check`
|
||||
- [x] `version`
|
||||
- [ ] `config`
|
||||
- [ ] `cp`
|
||||
|
@ -1,7 +1,65 @@
|
||||
package app
|
||||
|
||||
import "github.com/urfave/cli/v2"
|
||||
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",
|
||||
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
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user