From 1b37d2d5f5e3a4b8c45481f082cb6f9d25cefdae Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Wed, 5 Jan 2022 17:32:58 +0100 Subject: [PATCH] fix: handle tags without images gracefully --- cli/recipe/upgrade.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cli/recipe/upgrade.go b/cli/recipe/upgrade.go index b69481c2..247a8d18 100644 --- a/cli/recipe/upgrade.go +++ b/cli/recipe/upgrade.go @@ -115,20 +115,20 @@ You may invoke this command in "wizard" mode and be prompted for input: } logrus.Debugf("retrieved %s from remote registry for %s", regVersions, image) - if strings.Contains(image, "library") { - // ParseNormalizedNamed prepends 'library' to images like nginx:, - // postgres:, i.e. images which do not have a username in the - // first position of the string - image = strings.Split(image, "/")[1] - } - semverLikeTag := true - if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { - logrus.Debugf("%s not considered semver-like", img.(reference.NamedTagged).Tag()) - semverLikeTag = false + image = recipePkg.StripTagMeta(image) + + switch img.(type) { + case reference.NamedTagged: + if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { + logrus.Debugf("%s not considered semver-like", img.(reference.NamedTagged).Tag()) + } + default: + logrus.Warnf("unable to read tag for image %s, is it missing? skipping upgrade for %s", image, service.Name) + continue } tag, err := tagcmp.Parse(img.(reference.NamedTagged).Tag()) - if err != nil && semverLikeTag { + if err != nil { logrus.Fatal(err) } logrus.Debugf("parsed %s for %s", tag, service.Name) @@ -148,7 +148,7 @@ You may invoke this command in "wizard" mode and be prompted for input: sort.Sort(tagcmp.ByTagDesc(compatible)) - if len(compatible) == 0 && semverLikeTag { + if len(compatible) == 0 { logrus.Info(fmt.Sprintf("no new versions available for %s, %s is the latest", image, tag)) continue // skip on to the next tag and don't update any compose files }