fix: check published version properly

Resulted in a refactor to a new lint package.
This commit is contained in:
decentral1se 2021-12-26 00:00:19 +01:00
parent ba8138079f
commit 9a1cf258a5
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
5 changed files with 36 additions and 30 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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)