82 lines
2.1 KiB
Go
82 lines
2.1 KiB
Go
package app
|
|
|
|
import (
|
|
"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"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var appCheckCommand = cli.Command{
|
|
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,
|
|
internal.ChaosFlag,
|
|
internal.OfflineFlag,
|
|
},
|
|
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)
|
|
}
|
|
|
|
if !internal.Chaos {
|
|
if err := recipePkg.EnsureIsClean(app.Recipe); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
if !internal.Offline {
|
|
if err := recipePkg.EnsureUpToDate(app.Recipe); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := recipePkg.EnsureLatest(app.Recipe); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|
|
|
|
tableCol := []string{"recipe env sample", "app env"}
|
|
table := formatter.CreateTable(tableCol)
|
|
|
|
envVars, err := config.CheckEnv(app)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
for _, envVar := range envVars {
|
|
if envVar.Present {
|
|
table.Append([]string{envVar.Name, "✅"})
|
|
} else {
|
|
table.Append([]string{envVar.Name, "❌"})
|
|
}
|
|
}
|
|
|
|
table.Render()
|
|
|
|
return nil
|
|
},
|
|
}
|