feat: support version/upgrade listing

Closes coop-cloud/organising#130.
This commit is contained in:
2021-10-08 09:51:47 +02:00
parent 98ffc210e1
commit dde8afcd43
6 changed files with 89 additions and 34 deletions

View File

@ -1,6 +1,7 @@
package recipe
import (
"errors"
"fmt"
"coopcloud.tech/abra/cli/internal"
@ -11,20 +12,21 @@ import (
)
var recipeSyncCommand = &cli.Command{
Name: "sync",
Usage: "Ensure recipe version labels are up-to-date",
Aliases: []string{"s"},
Name: "sync",
Usage: "Ensure recipe version labels are up-to-date",
Aliases: []string{"s"},
ArgsUsage: "<recipe> <version>",
Description: `
This command will generate labels for the main recipe service (i.e. the service
named "app", by convention) which corresponds to the following format:
This command will generate labels for the main recipe service (i.e. by
convention, typically the service named "app") which corresponds to the
following format:
coop-cloud.${STACK_NAME}.version=${RECIPE_TAG}
coop-cloud.${STACK_NAME}.version=<version>
The ${RECIPE_TAG} is determined by the recipe maintainer and is retrieved by
this command by asking for the list of git tags on the local git repository.
The <recipe> configuration will be updated on the local file system.
The <version> is determined by the recipe maintainer and is specified on the
command-line. The <recipe> configuration will be updated on the local file
system.
`,
ArgsUsage: "<recipe>",
BashComplete: func(c *cli.Context) {
catl, err := catalogue.ReadRecipeCatalogue()
if err != nil {
@ -38,10 +40,17 @@ The <recipe> configuration will be updated on the local file system.
}
},
Action: func(c *cli.Context) error {
if c.Args().Len() != 2 {
internal.ShowSubcommandHelpAndError(c, errors.New("missing <recipe>/<version> arguments?"))
}
recipe := internal.ValidateRecipe(c)
mainService := "app"
// TODO: validate with tagcmp when new commits come in
// See https://git.coopcloud.tech/coop-cloud/abra/pulls/109
nextTag := c.Args().Get(1)
mainService := "app"
var services []string
hasAppService := false
for _, service := range recipe.Config.Services {
@ -67,24 +76,12 @@ The <recipe> configuration will be updated on the local file system.
logrus.Debugf("selecting '%s' as the service to sync version labels", mainService)
tags, err := recipe.Tags()
if err != nil {
logrus.Fatal(err)
}
if len(tags) == 0 {
logrus.Fatalf("no tags detected for '%s'", recipe.Name)
}
latestTag := tags[len(tags)-1]
logrus.Infof("choosing '%s' as latest tag for recipe '%s'", latestTag, recipe.Name)
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", latestTag)
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", nextTag)
if err := recipe.UpdateLabel(mainService, label); err != nil {
logrus.Fatal(err)
}
logrus.Infof("added label '%s' to service '%s'", label, mainService)
logrus.Infof("synced label '%s' to service '%s'", label, mainService)
return nil
},