forked from toolshed/abra
		
	refactor: centralise tag meta stripping
This commit is contained in:
		@ -1,8 +1,6 @@
 | 
			
		||||
package app
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/cli/internal"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/autocomplete"
 | 
			
		||||
	"coopcloud.tech/abra/pkg/client"
 | 
			
		||||
@ -22,9 +20,8 @@ func getImagePath(image string) (string, error) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	path := reference.Path(img)
 | 
			
		||||
	if strings.Contains(path, "library") {
 | 
			
		||||
		path = strings.Split(path, "/")[1]
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	path = recipe.StripTagMeta(path)
 | 
			
		||||
 | 
			
		||||
	logrus.Debugf("parsed %s from %s", path, image)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -2,9 +2,9 @@ package internal
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
	recipePkg "coopcloud.tech/abra/pkg/recipe"
 | 
			
		||||
	"github.com/AlecAivazis/survey/v2"
 | 
			
		||||
	"github.com/docker/distribution/reference"
 | 
			
		||||
	"github.com/sirupsen/logrus"
 | 
			
		||||
@ -94,9 +94,7 @@ func GetMainAppImage(recipe recipe.Recipe) (string, error) {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			path = reference.Path(img)
 | 
			
		||||
			if strings.Contains(path, "library") {
 | 
			
		||||
				path = strings.Split(path, "/")[1]
 | 
			
		||||
			}
 | 
			
		||||
			path = recipePkg.StripTagMeta(path)
 | 
			
		||||
 | 
			
		||||
			return path, nil
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -138,9 +138,8 @@ func getImageVersions(recipe recipe.Recipe) (map[string]string, error) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		path := reference.Path(img)
 | 
			
		||||
		if strings.Contains(path, "library") {
 | 
			
		||||
			path = strings.Split(path, "/")[1]
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		path = recipePkg.StripTagMeta(path)
 | 
			
		||||
 | 
			
		||||
		var tag string
 | 
			
		||||
		switch img.(type) {
 | 
			
		||||
 | 
			
		||||
@ -165,6 +165,9 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
 | 
			
		||||
// UpdateTag updates a recipe tag
 | 
			
		||||
func (r Recipe) UpdateTag(image, tag string) error {
 | 
			
		||||
	pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name)
 | 
			
		||||
 | 
			
		||||
	image = StripTagMeta(image)
 | 
			
		||||
 | 
			
		||||
	if err := compose.UpdateTag(pattern, image, tag, r.Name); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
@ -973,9 +976,8 @@ func GetRecipeVersions(recipeName, registryUsername, registryPassword string) (R
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			path := reference.Path(img)
 | 
			
		||||
			if strings.Contains(path, "library") {
 | 
			
		||||
				path = strings.Split(path, "/")[1]
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			path = StripTagMeta(path)
 | 
			
		||||
 | 
			
		||||
			var tag string
 | 
			
		||||
			switch img.(type) {
 | 
			
		||||
@ -1041,3 +1043,22 @@ func GetRecipeCatalogueVersions(recipeName string, catl RecipeCatalogue) ([]stri
 | 
			
		||||
 | 
			
		||||
	return versions, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// StripTagMeta strips front-matter image tag data that we don't need for parsing.
 | 
			
		||||
func StripTagMeta(image string) string {
 | 
			
		||||
	originalImage := image
 | 
			
		||||
 | 
			
		||||
	if strings.Contains(image, "docker.io") {
 | 
			
		||||
		image = strings.Split(image, "/")[1]
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if strings.Contains(image, "library") {
 | 
			
		||||
		image = strings.Split(image, "/")[1]
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if originalImage != image {
 | 
			
		||||
		logrus.Debugf("stripped %s to %s for parsing", originalImage, image)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return image
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user