feat: support tag upgrades without semver-like tags

This commit is contained in:
decentral1se 2021-08-10 08:24:36 +02:00
parent e39c6a05be
commit a12b53abab
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 21 additions and 6 deletions

View File

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