forked from toolshed/abra
refactor: put StripTagMeta into formatter package
Avoid circular import.
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
loader "coopcloud.tech/abra/pkg/upstream/stack"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
@ -57,7 +58,7 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
composeImage := reference.Path(img)
|
||||
composeImage := formatter.StripTagMeta(reference.Path(img))
|
||||
|
||||
logrus.Debugf("parsed %s from %s", composeTag, service.Image)
|
||||
|
||||
@ -74,7 +75,7 @@ func UpdateTag(pattern, image, tag, recipeName string) (bool, error) {
|
||||
logrus.Debugf("updating %s to %s in %s", old, new, compose.Filename)
|
||||
|
||||
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0764); err != nil {
|
||||
return true, err
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"github.com/docker/go-units"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func ShortenID(str string) string {
|
||||
@ -49,3 +50,22 @@ func CreateProgressbar(length int, title string) *progressbar.ProgressBar {
|
||||
progressbar.OptionSetDescription(title),
|
||||
)
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
|
||||
func (r Recipe) UpdateTag(image, tag string) (bool, error) {
|
||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.RECIPES_DIR, r.Name)
|
||||
|
||||
image = StripTagMeta(image)
|
||||
image = formatter.StripTagMeta(image)
|
||||
|
||||
ok, err := compose.UpdateTag(pattern, image, tag, r.Name)
|
||||
if err != nil {
|
||||
@ -983,7 +983,7 @@ func GetRecipeVersions(recipeName, registryUsername, registryPassword string) (R
|
||||
|
||||
path := reference.Path(img)
|
||||
|
||||
path = StripTagMeta(path)
|
||||
path = formatter.StripTagMeta(path)
|
||||
|
||||
var tag string
|
||||
switch img.(type) {
|
||||
@ -1050,25 +1050,6 @@ 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
|
||||
}
|
||||
|
||||
// EnsureCatalogue ensures that the catalogue is cloned locally & present.
|
||||
func EnsureCatalogue() error {
|
||||
catalogueDir := path.Join(config.ABRA_DIR, "catalogue")
|
||||
|
Reference in New Issue
Block a user