refactor: put StripTagMeta into formatter package
Avoid circular import.
This commit is contained in:
parent
7a66a90ecb
commit
f9a2c1d58f
|
@ -23,7 +23,7 @@ func getImagePath(image string) (string, error) {
|
|||
|
||||
path := reference.Path(img)
|
||||
|
||||
path = recipe.StripTagMeta(path)
|
||||
path = formatter.StripTagMeta(path)
|
||||
|
||||
logrus.Debugf("parsed %s from %s", path, image)
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ package internal
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"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,7 +94,7 @@ func GetMainAppImage(recipe recipe.Recipe) (string, error) {
|
|||
}
|
||||
|
||||
path = reference.Path(img)
|
||||
path = recipePkg.StripTagMeta(path)
|
||||
path = formatter.StripTagMeta(path)
|
||||
|
||||
return path, nil
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ func getImageVersions(recipe recipe.Recipe) (map[string]string, error) {
|
|||
|
||||
path := reference.Path(img)
|
||||
|
||||
path = recipePkg.StripTagMeta(path)
|
||||
path = formatter.StripTagMeta(path)
|
||||
|
||||
var tag string
|
||||
switch img.(type) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"coopcloud.tech/abra/pkg/autocomplete"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/tagcmp"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
|
@ -119,7 +120,7 @@ You may invoke this command in "wizard" mode and be prompted for input:
|
|||
}
|
||||
logrus.Debugf("retrieved %s from remote registry for %s", regVersions, image)
|
||||
|
||||
image = recipePkg.StripTagMeta(image)
|
||||
image = formatter.StripTagMeta(image)
|
||||
|
||||
switch img.(type) {
|
||||
case reference.NamedTagged:
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue