From a12b53abab508c3af19a9024963cce7ea40797a0 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Tue, 10 Aug 2021 08:24:36 +0200 Subject: [PATCH] feat: support tag upgrades without semver-like tags --- cli/recipe/recipe.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/cli/recipe/recipe.go b/cli/recipe/recipe.go index 22dcef28a..853dc7d32 100644 --- a/cli/recipe/recipe.go +++ b/cli/recipe/recipe.go @@ -166,8 +166,6 @@ var recipeUpgradeCommand = &cli.Command{ } for _, service := range compose.Services { - var compatible []tagcmp.Tag - catlVersions, err := catalogue.VersionsOfService(recipe, service.Name) if err != nil { logrus.Fatal(err) @@ -191,15 +189,21 @@ var recipeUpgradeCommand = &cli.Command{ image = strings.Split(image, "/")[1] } + semverLikeTag := true + if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { + semverLikeTag = false + } + tag, err := tagcmp.Parse(img.(reference.NamedTagged).Tag()) - if err != nil { + if err != nil && semverLikeTag { logrus.Fatal(err) } + var compatible []tagcmp.Tag for _, regVersion := range regVersions { other, err := tagcmp.Parse(regVersion.Name) if err != nil { - continue + continue // skip tags that cannot be parsed } if tag.IsCompatible(other) && tag.IsLessThan(other) && !tag.Equals(other) { @@ -209,7 +213,7 @@ var recipeUpgradeCommand = &cli.Command{ sort.Sort(tagcmp.ByTag(compatible)) - if len(compatible) == 0 { + if len(compatible) == 0 && semverLikeTag { 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 } @@ -227,8 +231,18 @@ var recipeUpgradeCommand = &cli.Command{ } } - var upgradeTag string msg := fmt.Sprintf("Which tag would you like to upgrade to? (service: %s, tag: %s)", service.Name, tag) + if !tagcmp.IsParsable(img.(reference.NamedTagged).Tag()) { + tag := img.(reference.NamedTagged).Tag() + logrus.Warning(fmt.Sprintf("Unable to determine versioning semantics of '%s', listing all tags...", tag)) + msg = fmt.Sprintf("Which tag would you like to upgrade to? (service: %s, tag: %s)", service.Name, tag) + compatibleStrings = []string{} + for _, regVersion := range regVersions { + compatibleStrings = append(compatibleStrings, regVersion.Name) + } + } + + var upgradeTag string prompt := &survey.Select{ Message: msg, Options: compatibleStrings, @@ -236,6 +250,7 @@ var recipeUpgradeCommand = &cli.Command{ if err := survey.AskOne(prompt, &upgradeTag); err != nil { logrus.Fatal(err) } + config.UpdateAppComposeTag(recipe, image, upgradeTag) }