From 11ef64ead3ad967eb027c057f5e537934a03c69f Mon Sep 17 00:00:00 2001 From: decentral1se Date: Fri, 6 Aug 2021 15:40:23 +0200 Subject: [PATCH] WIP: abra recipe upgrade on the way --- catalogue/catalogue.go | 24 ++++++++++++++++++++++++ cli/recipe/recipe.go | 27 ++++++++++++++++++++++++++- client/registry.go | 19 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 client/registry.go diff --git a/catalogue/catalogue.go b/catalogue/catalogue.go index 151bba62..1ad806b4 100644 --- a/catalogue/catalogue.go +++ b/catalogue/catalogue.go @@ -219,3 +219,27 @@ func readAppsCatalogueWeb(target interface{}) error { return nil } + +func VersionsOfService(recipe, serviceName string) ([]string, error) { + catl, err := ReadAppsCatalogue() + if err != nil { + return nil, err + } + + app, ok := catl[recipe] + if !ok { + return nil, fmt.Errorf("recipe '%s' does not exist?", recipe) + } + + versions := []string{} + alreadySeen := make(map[string]bool) + for version := range app.Versions { + appVersion := app.Versions[version][serviceName].Tag + if _, ok := alreadySeen[appVersion]; !ok { + alreadySeen[appVersion] = true + versions = append(versions, appVersion) + } + } + + return versions, nil +} diff --git a/cli/recipe/recipe.go b/cli/recipe/recipe.go index ec64ed92..c62aa217 100644 --- a/cli/recipe/recipe.go +++ b/cli/recipe/recipe.go @@ -158,7 +158,32 @@ 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 + + type existingTags struct { + AppCatalogueTags map[string]string + RegistryTags map[string]string + RecipeSkipTags map[string]string + } + + pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, recipe) + composeFiles, err := filepath.Glob(pattern) + if err != nil { + logrus.Fatal(err) + } + + opts := options.Deploy{Composefiles: composeFiles} + compose, err := loader.LoadComposefile(opts) + if err != nil { + logrus.Fatal(err) + } + + for _, service := range compose.Services { + _, err := catalogue.VersionsOfService(recipe, service.Name) + if err != nil { + logrus.Fatal(err) + } + } + // TODO return nil }, } diff --git a/client/registry.go b/client/registry.go new file mode 100644 index 00000000..30ef1b67 --- /dev/null +++ b/client/registry.go @@ -0,0 +1,19 @@ +package client + +import ( + "github.com/docker/distribution/reference" +) + +type Tag struct { + Layer string + Name string +} + +type Tags []Tag + +var registryURL = "https://registry.hub.docker.com/v1/repositories/%s/tags" + +func ReadRegistryTags(image reference.Named, target interface{}) ([]string, error) { + // tagsUrl := fmt.Sprintf(registryURL, image.Name()) + return nil, nil +}