feat: lint before deploy/upgrade/rollback
See coop-cloud/organising#254.
This commit is contained in:
parent
a84a5bc320
commit
8735a8f0ea
|
@ -45,6 +45,15 @@ recipes.
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
stackName := app.StackName()
|
stackName := app.StackName()
|
||||||
|
|
||||||
|
r, err := recipe.Get(app.Type)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := recipe.LintForErrors(r); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -49,6 +49,15 @@ recipes.
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
stackName := app.StackName()
|
stackName := app.StackName()
|
||||||
|
|
||||||
|
r, err := recipe.Get(app.Type)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := recipe.LintForErrors(r); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -22,6 +22,15 @@ func DeployAction(c *cli.Context) error {
|
||||||
app := ValidateApp(c)
|
app := ValidateApp(c)
|
||||||
stackName := app.StackName()
|
stackName := app.StackName()
|
||||||
|
|
||||||
|
r, err := recipe.Get(app.Type)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := recipe.LintForErrors(r); err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"coopcloud.tech/tagcmp"
|
"coopcloud.tech/tagcmp"
|
||||||
"github.com/docker/distribution/reference"
|
"github.com/docker/distribution/reference"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Warn = "warn"
|
var Warn = "warn"
|
||||||
|
@ -122,6 +123,29 @@ var LintRules = map[string][]LintRule{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LintForErrors(recipe Recipe) error {
|
||||||
|
logrus.Debugf("linting for critical errors in %s configs", recipe.Name)
|
||||||
|
|
||||||
|
for level := range LintRules {
|
||||||
|
if level != "error" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, rule := range LintRules[level] {
|
||||||
|
ok, err := rule.Function(recipe)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("lint error in %s configs: \"%s\" failed lint checks (%s)", recipe.Name, rule.Description, rule.Ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logrus.Debugf("linting successful, %s is well configured", recipe.Name)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func LintComposeVersion(recipe Recipe) (bool, error) {
|
func LintComposeVersion(recipe Recipe) (bool, error) {
|
||||||
if recipe.Config.Version == "3.8" {
|
if recipe.Config.Version == "3.8" {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
|
Loading…
Reference in New Issue