diff --git a/go.mod b/go.mod index 12e978c1..39740e2d 100644 --- a/go.mod +++ b/go.mod @@ -28,6 +28,7 @@ require ( github.com/containerd/containerd v1.5.9 // indirect github.com/containers/image v3.0.2+incompatible github.com/containers/storage v1.38.2 // indirect + github.com/coreos/go-semver v0.3.0 github.com/decentral1se/passgen v1.0.1 github.com/docker/docker-credential-helpers v0.6.4 // indirect github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect diff --git a/go.sum b/go.sum index 7ada5c83..ffe4a4c0 100644 --- a/go.sum +++ b/go.sum @@ -298,6 +298,7 @@ github.com/coreos/go-iptables v0.4.5/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmeka github.com/coreos/go-iptables v0.5.0/go.mod h1:/mVI274lEDI2ns62jHCDnCyBF9Iwsmekav8Dbxlm1MU= github.com/coreos/go-oidc v2.1.0+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20161114122254-48702e0da86b/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index 1ec9112f..ae779025 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -8,6 +8,7 @@ import ( "os" "path" "path/filepath" + "sort" "strconv" "strings" "time" @@ -22,6 +23,7 @@ import ( "coopcloud.tech/abra/pkg/upstream/stack" loader "coopcloud.tech/abra/pkg/upstream/stack" "coopcloud.tech/abra/pkg/web" + "github.com/coreos/go-semver/semver" composetypes "github.com/docker/cli/cli/compose/types" "github.com/docker/distribution/reference" "github.com/go-git/go-git/v5" @@ -1017,12 +1019,30 @@ func GetRecipeVersions(recipeName string, conf *runtime.Config) (RecipeVersions, if err != nil { return versions, err } + sortRecipeVersions(versions) logrus.Debugf("collected %s for %s", versions, recipeName) return versions, nil } +// sortRecipeVersions sorts the recipe semver versions +func sortRecipeVersions(versions RecipeVersions) { + sort.Slice(versions, func(i, j int) bool { + version1 := semver.New(getVersionString(versions[i])) + version2 := semver.New(getVersionString(versions[j])) + return version1.Compare(*version2) < 0 + }) +} + +// getVersionString returns the version string from RecipeVersions +func getVersionString(versionMap map[string]map[string]ServiceMeta) string { + // Assuming there's only one key in versionMap + for k := range versionMap { + return k + } + return "" +} // GetRecipeCatalogueVersions list the recipe versions listed in the recipe catalogue. func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]string, error) { var versions []string