parent
b4fd39828f
commit
1d0b1c9a50
|
@ -3,11 +3,12 @@ package app
|
|||
import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"sort"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -15,9 +16,21 @@ import (
|
|||
)
|
||||
|
||||
var appCheckCommand = cli.Command{
|
||||
Name: "check",
|
||||
Aliases: []string{"chk"},
|
||||
Usage: "Check if an app is configured correctly",
|
||||
Name: "check",
|
||||
Aliases: []string{"chk"},
|
||||
Usage: "Ensure an app is well configured",
|
||||
Description: `
|
||||
This command compares env vars in both the app ".env" and recipe ".env.sample"
|
||||
file.
|
||||
|
||||
The goal is to ensure that recipe ".env.sample" env vars are defined in your
|
||||
app ".env" file. Only env var definitions in the ".env.sample" which are
|
||||
uncommented, e.g. "FOO=bar" are checked. If an app ".env" file does not include
|
||||
these env vars, then "check" will complain.
|
||||
|
||||
Recipe maintainers may or may not provide defaults for env vars within their
|
||||
recipes regardless of commenting or not (e.g. through the use of
|
||||
${FOO:<default>} syntax). "check" does not confirm or deny this for you.`,
|
||||
ArgsUsage: "<domain>",
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
|
@ -62,19 +75,25 @@ var appCheckCommand = cli.Command{
|
|||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
var missing []string
|
||||
for k := range envSample {
|
||||
if _, ok := app.Env[k]; !ok {
|
||||
missing = append(missing, k)
|
||||
var keys []string
|
||||
for key := range envSample {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
sort.Strings(keys)
|
||||
|
||||
tableCol := []string{"recipe env sample", "app env"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
|
||||
for _, key := range keys {
|
||||
if _, ok := app.Env[key]; ok {
|
||||
table.Append([]string{key, "✅"})
|
||||
} else {
|
||||
table.Append([]string{key, "❌"})
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
table.Render()
|
||||
|
||||
return nil
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue