forked from coop-cloud/abra
WIP first run at the upgrade command
This commit is contained in:
parent
a18a9493f2
commit
7b1a6dd4d7
@ -12,8 +12,11 @@ import (
|
||||
"coopcloud.tech/abra/catalogue"
|
||||
"coopcloud.tech/abra/cli/formatter"
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/client"
|
||||
"coopcloud.tech/abra/config"
|
||||
"coopcloud.tech/abra/tagcmp"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -155,7 +158,71 @@ var recipeUpgradeCommand = &cli.Command{
|
||||
if recipe == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
|
||||
}
|
||||
// TODO: part 1 of https://git.coopcloud.tech/coop-cloud/go-abra/issues/39#issuecomment-8066
|
||||
|
||||
compose, err := config.GetAppComposeFiles(recipe)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
for _, service := range compose.Services {
|
||||
var compatible []tagcmp.Tag
|
||||
|
||||
// TODO: use to filter registry versions
|
||||
// catlVersions, err := catalogue.VersionsOfService(recipe, service.Name)
|
||||
// if err != nil {
|
||||
// logrus.Fatal(err)
|
||||
// }
|
||||
|
||||
img, err := reference.ParseNormalizedNamed(service.Image)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
image := reference.Path(img.(reference.Named))
|
||||
regVersions, err := client.GetRegistryTags(image)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
tag, err := tagcmp.Parse(img.(reference.NamedTagged).Tag())
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
for _, regVersion := range regVersions {
|
||||
other, err := tagcmp.Parse(regVersion.Name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if tag.IsCompatible(other) && tag.IsLessThan(other) && !tag.Equals(other) {
|
||||
compatible = append(compatible, other)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(tagcmp.ByTag(compatible))
|
||||
|
||||
if len(compatible) == 0 {
|
||||
logrus.Info(fmt.Sprintf("No new versions available for '%s', '%s' is the latest", image, tag))
|
||||
break
|
||||
}
|
||||
|
||||
var compatibleStrings []string
|
||||
for _, compat := range compatible {
|
||||
compatibleStrings = append(compatibleStrings, compat.String())
|
||||
}
|
||||
|
||||
var upgradeTag string
|
||||
msg := fmt.Sprintf("Which tag would you like to upgrade to? (service: %s, tag: %s)", service.Name, tag)
|
||||
prompt := &survey.Select{
|
||||
Message: msg,
|
||||
Options: compatibleStrings,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &upgradeTag); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user