forked from coop-cloud/abra
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path"
|
|
"strings"
|
|
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
"coopcloud.tech/abra/pkg/config"
|
|
"coopcloud.tech/abra/pkg/recipe"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var appCheckCommand = cli.Command{
|
|
Name: "check",
|
|
Aliases: []string{"chk"},
|
|
Usage: "Check if an app is configured correctly",
|
|
ArgsUsage: "<domain>",
|
|
Flags: []cli.Flag{
|
|
internal.DebugFlag,
|
|
},
|
|
Before: internal.SubCommandBefore,
|
|
BashComplete: autocomplete.AppNameComplete,
|
|
Action: func(c *cli.Context) error {
|
|
app := internal.ValidateApp(c)
|
|
|
|
if err := recipe.EnsureExists(app.Recipe); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
envSamplePath := path.Join(config.RECIPES_DIR, app.Recipe, ".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 := app.Env[k]; !ok {
|
|
missing = append(missing, k)
|
|
}
|
|
}
|
|
|
|
if len(missing) > 0 {
|
|
missingEnvVars := strings.Join(missing, ", ")
|
|
logrus.Fatalf("%s is missing %s", app.Path, missingEnvVars)
|
|
}
|
|
|
|
logrus.Infof("all necessary environment variables defined for %s", app.Name)
|
|
|
|
return nil
|
|
},
|
|
}
|