forked from toolshed/abra
refactor: use central logger
This commit is contained in:
@ -19,6 +19,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||
"coopcloud.tech/abra/pkg/limit"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
loader "coopcloud.tech/abra/pkg/upstream/stack"
|
||||
"coopcloud.tech/abra/pkg/web"
|
||||
@ -27,7 +28,6 @@ import (
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RecipeCatalogueURL is the only current recipe catalogue available.
|
||||
@ -81,7 +81,7 @@ func (r RecipeMeta) LatestVersion() string {
|
||||
version = tag
|
||||
}
|
||||
|
||||
logrus.Debugf("choosing %s as latest version of %s", version, r.Name)
|
||||
log.Debugf("choosing %s as latest version of %s", version, r.Name)
|
||||
|
||||
return version
|
||||
}
|
||||
@ -206,7 +206,7 @@ func (r Recipe) Tags() ([]string, error) {
|
||||
return tags, err
|
||||
}
|
||||
|
||||
logrus.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name)
|
||||
log.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name)
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
@ -284,7 +284,7 @@ func EnsureExists(recipeName string) error {
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
if _, err := os.Stat(recipeDir); os.IsNotExist(err) {
|
||||
logrus.Debugf("%s does not exist, attemmpting to clone", recipeDir)
|
||||
log.Debugf("%s does not exist, attemmpting to clone", recipeDir)
|
||||
url := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, recipeName)
|
||||
if err := gitPkg.Clone(recipeDir, url); err != nil {
|
||||
return err
|
||||
@ -330,7 +330,7 @@ func EnsureVersion(recipeName, version string) error {
|
||||
|
||||
joinedTags := strings.Join(parsedTags, ", ")
|
||||
if joinedTags != "" {
|
||||
logrus.Debugf("read %s as tags for recipe %s", joinedTags, recipeName)
|
||||
log.Debugf("read %s as tags for recipe %s", joinedTags, recipeName)
|
||||
}
|
||||
|
||||
if tagRef.String() == "" {
|
||||
@ -351,7 +351,7 @@ func EnsureVersion(recipeName, version string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("successfully checked %s out to %s in %s", recipeName, tagRef.Short(), recipeDir)
|
||||
log.Debugf("successfully checked %s out to %s in %s", recipeName, tagRef.Short(), recipeDir)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -403,7 +403,7 @@ func EnsureLatest(recipeName string) error {
|
||||
}
|
||||
|
||||
if err := worktree.Checkout(checkOutOpts); err != nil {
|
||||
logrus.Debugf("failed to check out %s in %s", branch, recipeDir)
|
||||
log.Debugf("failed to check out %s in %s", branch, recipeDir)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -472,7 +472,7 @@ func GetRecipeFeaturesAndCategory(recipeName string) (Features, string, error) {
|
||||
|
||||
readmePath := path.Join(config.RECIPES_DIR, recipeName, "README.md")
|
||||
|
||||
logrus.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
|
||||
log.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
|
||||
|
||||
readmeFS, err := ioutil.ReadFile(readmePath)
|
||||
if err != nil {
|
||||
@ -553,9 +553,9 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, error) {
|
||||
|
||||
if len(imgFields) < 3 {
|
||||
if imageRowString != "" {
|
||||
logrus.Warnf("%s image meta has incorrect format: %s", recipeName, imageRowString)
|
||||
log.Warnf("%s image meta has incorrect format: %s", recipeName, imageRowString)
|
||||
} else {
|
||||
logrus.Warnf("%s image meta is empty?", recipeName)
|
||||
log.Warnf("%s image meta is empty?", recipeName)
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
@ -567,13 +567,13 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, error) {
|
||||
|
||||
imageName, err := GetStringInBetween(recipeName, imgString, "[", "]")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
img.Image = strings.ReplaceAll(imageName, "`", "")
|
||||
|
||||
imageURL, err := GetStringInBetween(recipeName, imgString, "(", ")")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
img.URL = imageURL
|
||||
|
||||
@ -612,7 +612,7 @@ func EnsureUpToDate(recipeName string) error {
|
||||
}
|
||||
|
||||
if len(remotes) == 0 {
|
||||
logrus.Debugf("cannot ensure %s is up-to-date, no git remotes configured", recipeName)
|
||||
log.Debugf("cannot ensure %s is up-to-date, no git remotes configured", recipeName)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -645,7 +645,7 @@ func EnsureUpToDate(recipeName string) error {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("fetched latest git changes for %s", recipeName)
|
||||
log.Debugf("fetched latest git changes for %s", recipeName)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -682,7 +682,7 @@ func readRecipeCatalogueFS(target interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON)
|
||||
log.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -711,7 +711,7 @@ func VersionsOfService(recipe, serviceName string, offline bool) ([]string, erro
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("detected versions %s for %s", strings.Join(versions, ", "), recipe)
|
||||
log.Debugf("detected versions %s for %s", strings.Join(versions, ", "), recipe)
|
||||
|
||||
return versions, nil
|
||||
}
|
||||
@ -738,7 +738,7 @@ func GetRecipeMeta(recipeName string, offline bool) (RecipeMeta, error) {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("recipe metadata retrieved for %s", recipeName)
|
||||
log.Debugf("recipe metadata retrieved for %s", recipeName)
|
||||
|
||||
return recipeMeta, nil
|
||||
}
|
||||
@ -831,7 +831,7 @@ func ReadReposMetadata() (RepoCatalogue, error) {
|
||||
|
||||
pagedURL := fmt.Sprintf("%s?page=%v", ReposMetadataURL, pageIdx)
|
||||
|
||||
logrus.Debugf("fetching repo metadata from %s", pagedURL)
|
||||
log.Debugf("fetching repo metadata from %s", pagedURL)
|
||||
|
||||
if err := web.ReadJSON(pagedURL, &reposList); err != nil {
|
||||
return reposMeta, err
|
||||
@ -869,7 +869,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
|
||||
versions := RecipeVersions{}
|
||||
recipeDir := path.Join(config.RECIPES_DIR, recipeName)
|
||||
|
||||
logrus.Debugf("attempting to open git repository in %s", recipeDir)
|
||||
log.Debugf("attempting to open git repository in %s", recipeDir)
|
||||
|
||||
repo, err := git.PlainOpen(recipeDir)
|
||||
if err != nil {
|
||||
@ -889,7 +889,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
|
||||
if err := gitTags.ForEach(func(ref *plumbing.Reference) (err error) {
|
||||
tag := strings.TrimPrefix(string(ref.Name()), "refs/tags/")
|
||||
|
||||
logrus.Debugf("processing %s for %s", tag, recipeName)
|
||||
log.Debugf("processing %s for %s", tag, recipeName)
|
||||
|
||||
checkOutOpts := &git.CheckoutOptions{
|
||||
Create: false,
|
||||
@ -897,11 +897,11 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
|
||||
Branch: plumbing.ReferenceName(ref.Name()),
|
||||
}
|
||||
if err := worktree.Checkout(checkOutOpts); err != nil {
|
||||
logrus.Debugf("failed to check out %s in %s", tag, recipeDir)
|
||||
log.Debugf("failed to check out %s in %s", tag, recipeDir)
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("successfully checked out %s in %s", ref.Name(), recipeDir)
|
||||
log.Debugf("successfully checked out %s in %s", ref.Name(), recipeDir)
|
||||
|
||||
recipe, err := Get(recipeName, offline)
|
||||
if err != nil {
|
||||
@ -925,7 +925,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
|
||||
case reference.NamedTagged:
|
||||
tag = img.(reference.NamedTagged).Tag()
|
||||
case reference.Named:
|
||||
logrus.Warnf("%s service is missing image tag?", path)
|
||||
log.Warnf("%s service is missing image tag?", path)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -949,7 +949,7 @@ func GetRecipeVersions(recipeName string, offline bool) (RecipeVersions, error)
|
||||
|
||||
sortRecipeVersions(versions)
|
||||
|
||||
logrus.Debugf("collected %s for %s", versions, recipeName)
|
||||
log.Debugf("collected %s for %s", versions, recipeName)
|
||||
|
||||
return versions, nil
|
||||
}
|
||||
@ -1036,7 +1036,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string) error {
|
||||
|
||||
recipeDir := path.Join(config.RECIPES_DIR, rm.Name)
|
||||
if err := gitPkg.Clone(recipeDir, rm.CloneURL); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ch <- rm.Name
|
||||
@ -1076,7 +1076,7 @@ func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error)
|
||||
if err := ensurePathExists(path); err != nil {
|
||||
return composeFiles, err
|
||||
}
|
||||
logrus.Debugf("no COMPOSE_FILE detected, loading default: %s", path)
|
||||
log.Debugf("no COMPOSE_FILE detected, loading default: %s", path)
|
||||
composeFiles = append(composeFiles, path)
|
||||
return composeFiles, nil
|
||||
}
|
||||
@ -1086,7 +1086,7 @@ func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error)
|
||||
if err := ensurePathExists(path); err != nil {
|
||||
return composeFiles, err
|
||||
}
|
||||
logrus.Debugf("COMPOSE_FILE detected, loading %s", path)
|
||||
log.Debugf("COMPOSE_FILE detected, loading %s", path)
|
||||
composeFiles = append(composeFiles, path)
|
||||
return composeFiles, nil
|
||||
}
|
||||
@ -1105,8 +1105,8 @@ func GetComposeFiles(recipe string, appEnv map[string]string) ([]string, error)
|
||||
composeFiles = append(composeFiles, path)
|
||||
}
|
||||
|
||||
logrus.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
|
||||
logrus.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
|
||||
log.Debugf("COMPOSE_FILE detected (%s), loading %s", composeFileEnvVar, strings.Join(envVars, ", "))
|
||||
log.Debugf("retrieved %s configs for %s", strings.Join(composeFiles, ", "), recipe)
|
||||
|
||||
return composeFiles, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user