diff --git a/cli/app/rollback.go b/cli/app/rollback.go index 5130a02f..506dcc96 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -6,6 +6,7 @@ import ( "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/catalogue" "coopcloud.tech/abra/pkg/config" + "coopcloud.tech/abra/pkg/lint" "coopcloud.tech/abra/pkg/recipe" stack "coopcloud.tech/abra/pkg/upstream/stack" "coopcloud.tech/tagcmp" @@ -50,7 +51,7 @@ recipes. logrus.Fatal(err) } - if err := recipe.LintForErrors(r); err != nil { + if err := lint.LintForErrors(r); err != nil { logrus.Fatal(err) } diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index e8250cd6..e9bfeed1 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -8,6 +8,7 @@ import ( "coopcloud.tech/abra/pkg/catalogue" "coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/config" + "coopcloud.tech/abra/pkg/lint" "coopcloud.tech/abra/pkg/recipe" stack "coopcloud.tech/abra/pkg/upstream/stack" "coopcloud.tech/tagcmp" @@ -54,7 +55,7 @@ recipes. logrus.Fatal(err) } - if err := recipe.LintForErrors(r); err != nil { + if err := lint.LintForErrors(r); err != nil { logrus.Fatal(err) } diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 9e19a05f..0a9d4d8a 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -10,6 +10,7 @@ import ( "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/dns" "coopcloud.tech/abra/pkg/git" + "coopcloud.tech/abra/pkg/lint" "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/abra/pkg/upstream/stack" "github.com/AlecAivazis/survey/v2" @@ -27,7 +28,7 @@ func DeployAction(c *cli.Context) error { logrus.Fatal(err) } - if err := recipe.LintForErrors(r); err != nil { + if err := lint.LintForErrors(r); err != nil { logrus.Fatal(err) } diff --git a/cli/recipe/lint.go b/cli/recipe/lint.go index bbc91f35..fad3829d 100644 --- a/cli/recipe/lint.go +++ b/cli/recipe/lint.go @@ -6,7 +6,7 @@ import ( "coopcloud.tech/abra/cli/formatter" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" - recipePkg "coopcloud.tech/abra/pkg/recipe" + "coopcloud.tech/abra/pkg/lint" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -26,8 +26,8 @@ var recipeLintCommand = &cli.Command{ hasError := false bar := formatter.CreateProgressbar(-1, "running recipe lint rules...") - for level := range recipePkg.LintRules { - for _, rule := range recipePkg.LintRules[level] { + for level := range lint.LintRules { + for _, rule := range lint.LintRules[level] { ok, err := rule.Function(recipe) if err != nil { logrus.Warn(err) diff --git a/pkg/recipe/lint.go b/pkg/lint/recipe.go similarity index 83% rename from pkg/recipe/lint.go rename to pkg/lint/recipe.go index c6d307d1..80a72c7c 100644 --- a/pkg/recipe/lint.go +++ b/pkg/lint/recipe.go @@ -1,4 +1,4 @@ -package recipe +package lint import ( "fmt" @@ -6,7 +6,9 @@ import ( "os" "path" + "coopcloud.tech/abra/pkg/catalogue" "coopcloud.tech/abra/pkg/config" + "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/tagcmp" "github.com/docker/distribution/reference" "github.com/sirupsen/logrus" @@ -15,7 +17,7 @@ import ( var Warn = "warn" var Critical = "critical" -type LintFunction func(Recipe) (bool, error) +type LintFunction func(recipe.Recipe) (bool, error) type LintRule struct { Ref string @@ -123,7 +125,7 @@ var LintRules = map[string][]LintRule{ }, } -func LintForErrors(recipe Recipe) error { +func LintForErrors(recipe recipe.Recipe) error { logrus.Debugf("linting for critical errors in %s configs", recipe.Name) for level := range LintRules { @@ -146,7 +148,7 @@ func LintForErrors(recipe Recipe) error { return nil } -func LintComposeVersion(recipe Recipe) (bool, error) { +func LintComposeVersion(recipe recipe.Recipe) (bool, error) { if recipe.Config.Version == "3.8" { return true, nil } @@ -154,7 +156,7 @@ func LintComposeVersion(recipe Recipe) (bool, error) { return true, nil } -func LintEnvConfigPresent(recipe Recipe) (bool, error) { +func LintEnvConfigPresent(recipe recipe.Recipe) (bool, error) { envSample := fmt.Sprintf("%s/%s/.env.sample", config.RECIPES_DIR, recipe.Name) if _, err := os.Stat(envSample); !os.IsNotExist(err) { return true, nil @@ -163,7 +165,7 @@ func LintEnvConfigPresent(recipe Recipe) (bool, error) { return false, nil } -func LintAppService(recipe Recipe) (bool, error) { +func LintAppService(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { if service.Name == "app" { return true, nil @@ -173,7 +175,7 @@ func LintAppService(recipe Recipe) (bool, error) { return false, nil } -func LintTraefikEnabled(recipe Recipe) (bool, error) { +func LintTraefikEnabled(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { for label := range service.Deploy.Labels { if label == "traefik.enable" { @@ -187,7 +189,7 @@ func LintTraefikEnabled(recipe Recipe) (bool, error) { return false, nil } -func LintHealthchecks(recipe Recipe) (bool, error) { +func LintHealthchecks(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { if service.HealthCheck == nil { return false, nil @@ -197,7 +199,7 @@ func LintHealthchecks(recipe Recipe) (bool, error) { return true, nil } -func LintAllImagesTagged(recipe Recipe) (bool, error) { +func LintAllImagesTagged(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { img, err := reference.ParseNormalizedNamed(service.Image) if err != nil { @@ -211,7 +213,7 @@ func LintAllImagesTagged(recipe Recipe) (bool, error) { return true, nil } -func LintNoUnstableTags(recipe Recipe) (bool, error) { +func LintNoUnstableTags(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { img, err := reference.ParseNormalizedNamed(service.Image) if err != nil { @@ -234,7 +236,7 @@ func LintNoUnstableTags(recipe Recipe) (bool, error) { return true, nil } -func LintSemverLikeTags(recipe Recipe) (bool, error) { +func LintSemverLikeTags(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { img, err := reference.ParseNormalizedNamed(service.Image) if err != nil { @@ -257,7 +259,7 @@ func LintSemverLikeTags(recipe Recipe) (bool, error) { return true, nil } -func LintImagePresent(recipe Recipe) (bool, error) { +func LintImagePresent(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { if service.Image == "" { return false, nil @@ -266,25 +268,26 @@ func LintImagePresent(recipe Recipe) (bool, error) { return true, nil } -func LintHasPublishedVersion(recipe Recipe) (bool, error) { - if err := EnsureUpToDate(recipe.Name); err != nil { - return false, err - } - - tags, err := recipe.Tags() +func LintHasPublishedVersion(recipe recipe.Recipe) (bool, error) { + catl, err := catalogue.ReadRecipeCatalogue() if err != nil { - return false, err + logrus.Fatal(err) } - if len(tags) == 0 { + versions, err := catalogue.GetRecipeCatalogueVersions(recipe.Name, catl) + if err != nil { + logrus.Fatal(err) + } + + if len(versions) == 0 { return false, nil } return true, nil } -func LintMetadataFilledIn(recipe Recipe) (bool, error) { - features, category, err := GetRecipeFeaturesAndCategory(recipe.Name) +func LintMetadataFilledIn(r recipe.Recipe) (bool, error) { + features, category, err := recipe.GetRecipeFeaturesAndCategory(r.Name) if err != nil { return false, err } @@ -304,7 +307,7 @@ func LintMetadataFilledIn(recipe Recipe) (bool, error) { return true, nil } -func LintAbraShVendors(recipe Recipe) (bool, error) { +func LintAbraShVendors(recipe recipe.Recipe) (bool, error) { for _, service := range recipe.Config.Services { if len(service.Configs) > 0 { abraSh := path.Join(config.RECIPES_DIR, recipe.Name, "abra.sh") @@ -319,7 +322,7 @@ func LintAbraShVendors(recipe Recipe) (bool, error) { return true, nil } -func LintHasRecipeRepo(recipe Recipe) (bool, error) { +func LintHasRecipeRepo(recipe recipe.Recipe) (bool, error) { url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipe.Name) res, err := http.Get(url)