diff --git a/cli/app/version.go b/cli/app/version.go index cf041826..ede9642c 100644 --- a/cli/app/version.go +++ b/cli/app/version.go @@ -23,7 +23,7 @@ func getImagePath(image string) (string, error) { path := reference.Path(img) - path = recipe.StripTagMeta(path) + path = formatter.StripTagMeta(path) logrus.Debugf("parsed %s from %s", path, image) diff --git a/cli/internal/recipe.go b/cli/internal/recipe.go index 30f13903..b4f01020 100644 --- a/cli/internal/recipe.go +++ b/cli/internal/recipe.go @@ -3,8 +3,8 @@ package internal import ( "fmt" + "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/recipe" - recipePkg "coopcloud.tech/abra/pkg/recipe" "github.com/AlecAivazis/survey/v2" "github.com/docker/distribution/reference" "github.com/sirupsen/logrus" @@ -94,7 +94,7 @@ func GetMainAppImage(recipe recipe.Recipe) (string, error) { } path = reference.Path(img) - path = recipePkg.StripTagMeta(path) + path = formatter.StripTagMeta(path) return path, nil } diff --git a/cli/recipe/release.go b/cli/recipe/release.go index a37849fa..727281e8 100644 --- a/cli/recipe/release.go +++ b/cli/recipe/release.go @@ -143,7 +143,7 @@ func getImageVersions(recipe recipe.Recipe) (map[string]string, error) { path := reference.Path(img) - path = recipePkg.StripTagMeta(path) + path = formatter.StripTagMeta(path) var tag string switch img.(type) { diff --git a/cli/recipe/upgrade.go b/cli/recipe/upgrade.go index ac05423b..49f08985 100644 --- a/cli/recipe/upgrade.go +++ b/cli/recipe/upgrade.go @@ -12,6 +12,7 @@ import ( "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/client" "coopcloud.tech/abra/pkg/config" + "coopcloud.tech/abra/pkg/formatter" recipePkg "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/tagcmp" "github.com/AlecAivazis/survey/v2" @@ -119,7 +120,7 @@ You may invoke this command in "wizard" mode and be prompted for input: } logrus.Debugf("retrieved %s from remote registry for %s", regVersions, image) - image = recipePkg.StripTagMeta(image) + image = formatter.StripTagMeta(image) switch img.(type) { case reference.NamedTagged: diff --git a/pkg/compose/compose.go b/pkg/compose/compose.go index a1e898c4..e207db5c 100644 --- a/pkg/compose/compose.go +++ b/pkg/compose/compose.go @@ -8,6 +8,7 @@ import ( "strings" "coopcloud.tech/abra/pkg/config" + "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/upstream/stack" loader "coopcloud.tech/abra/pkg/upstream/stack" composetypes "github.com/docker/cli/cli/compose/types" @@ -57,7 +58,7 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) { return false, nil } - composeImage := reference.Path(img) + composeImage := formatter.StripTagMeta(reference.Path(img)) logrus.Debugf("parsed %s from %s", composeTag, service.Image) @@ -74,7 +75,7 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) { logrus.Debugf("updating %s to %s in %s", old, new, compose.Filename) if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0764); err != nil { - return true, err + return false, err } } } diff --git a/pkg/formatter/formatter.go b/pkg/formatter/formatter.go index 0f6a9a84..b68887d3 100644 --- a/pkg/formatter/formatter.go +++ b/pkg/formatter/formatter.go @@ -8,6 +8,7 @@ import ( "github.com/docker/go-units" "github.com/olekukonko/tablewriter" "github.com/schollz/progressbar/v3" + "github.com/sirupsen/logrus" ) func ShortenID(str string) string { @@ -49,3 +50,22 @@ func CreateProgressbar(length int, title string) *progressbar.ProgressBar { progressbar.OptionSetDescription(title), ) } + +// StripTagMeta strips front-matter image tag data that we don't need for parsing. +func StripTagMeta(image string) string { + originalImage := image + + if strings.Contains(image, "docker.io") { + image = strings.Split(image, "/")[1] + } + + if strings.Contains(image, "library") { + image = strings.Split(image, "/")[1] + } + + if originalImage != image { + logrus.Debugf("stripped %s to %s for parsing", originalImage, image) + } + + return image +} diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index 01c8259b..db9c803e 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -166,7 +166,7 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error { func (r Recipe) UpdateTag(image, tag string) (bool, error) { pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name) - image = StripTagMeta(image) + image = formatter.StripTagMeta(image) ok, err := compose.UpdateTag(pattern, image, tag, r.Name) if err != nil { @@ -983,7 +983,7 @@ func GetRecipeVersions(recipeName, registryUsername, registryPassword string) (R path := reference.Path(img) - path = StripTagMeta(path) + path = formatter.StripTagMeta(path) var tag string switch img.(type) { @@ -1050,25 +1050,6 @@ func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]stri return versions, nil } -// StripTagMeta strips front-matter image tag data that we don't need for parsing. -func StripTagMeta(image string) string { - originalImage := image - - if strings.Contains(image, "docker.io") { - image = strings.Split(image, "/")[1] - } - - if strings.Contains(image, "library") { - image = strings.Split(image, "/")[1] - } - - if originalImage != image { - logrus.Debugf("stripped %s to %s for parsing", originalImage, image) - } - - return image -} - // EnsureCatalogue ensures that the catalogue is cloned locally & present. func EnsureCatalogue() error { catalogueDir := path.Join(config.ABRA_DIR, "catalogue")