refactor: use central logger

This commit is contained in:
2024-07-07 23:45:37 +02:00
parent cf8ff410cc
commit ef108d63e1
86 changed files with 903 additions and 889 deletions

View File

@ -22,7 +22,7 @@ import (
"github.com/docker/docker/api/types/filters"
dockerclient "github.com/docker/docker/client"
"github.com/sirupsen/logrus"
"coopcloud.tech/abra/pkg/log"
"github.com/urfave/cli"
)
@ -61,25 +61,25 @@ printed. To include major versions use the --major flag.
Action: func(c *cli.Context) error {
cl, err := client.New("default")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
stacks, err := stack.GetStacks(cl)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
for _, stackInfo := range stacks {
stackName := stackInfo.Name
recipeName, err := getLabel(cl, stackName, "recipe")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
if recipeName != "" {
_, err = getLatestUpgrade(cl, stackName, recipeName)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
}
}
@ -114,7 +114,7 @@ update chaos deployments use the "--chaos" flag. Use it with care.
Action: func(c *cli.Context) error {
cl, err := client.New("default")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
if !updateAll {
@ -122,7 +122,7 @@ update chaos deployments use the "--chaos" flag. Use it with care.
recipeName := c.Args().Get(1)
err = tryUpgrade(cl, stackName, recipeName)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
return nil
@ -130,19 +130,19 @@ update chaos deployments use the "--chaos" flag. Use it with care.
stacks, err := stack.GetStacks(cl)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
for _, stackInfo := range stacks {
stackName := stackInfo.Name
recipeName, err := getLabel(cl, stackName, "recipe")
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
err = tryUpgrade(cl, stackName, recipeName)
if err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
}
@ -167,7 +167,7 @@ func getLabel(cl *dockerclient.Client, stackName string, label string) (string,
}
}
logrus.Debugf("no %s label found for %s", label, stackName)
log.Debugf("no %s label found for %s", label, stackName)
return "", nil
}
@ -188,7 +188,7 @@ func getBoolLabel(cl *dockerclient.Client, stackName string, label string) (bool
return value, nil
}
logrus.Debugf("Boolean label %s could not be found for %s, set default to false.", label, stackName)
log.Debugf("Boolean label %s could not be found for %s, set default to false.", label, stackName)
return false, nil
}
@ -209,12 +209,12 @@ func getEnv(cl *dockerclient.Client, stackName string) (envfile.AppEnv, error) {
for _, envString := range envList {
splitString := strings.SplitN(envString, "=", 2)
if len(splitString) != 2 {
logrus.Debugf("can't separate key from value: %s (this variable is probably unset)", envString)
log.Debugf("can't separate key from value: %s (this variable is probably unset)", envString)
continue
}
k := splitString[0]
v := splitString[1]
logrus.Debugf("For %s read env %s with value: %s from docker service", stackName, k, v)
log.Debugf("For %s read env %s with value: %s from docker service", stackName, k, v)
envMap[k] = v
}
}
@ -236,14 +236,14 @@ func getLatestUpgrade(cl *dockerclient.Client, stackName string, recipeName stri
}
if len(availableUpgrades) == 0 {
logrus.Debugf("no available upgrades for %s", stackName)
log.Debugf("no available upgrades for %s", stackName)
return "", nil
}
var chosenUpgrade string
if len(availableUpgrades) > 0 {
chosenUpgrade = availableUpgrades[len(availableUpgrades)-1]
logrus.Infof("%s (%s) can be upgraded from version %s to %s", stackName, recipeName, deployedVersion, chosenUpgrade)
log.Infof("%s (%s) can be upgraded from version %s to %s", stackName, recipeName, deployedVersion, chosenUpgrade)
}
return chosenUpgrade, nil
@ -251,7 +251,7 @@ func getLatestUpgrade(cl *dockerclient.Client, stackName string, recipeName stri
// getDeployedVersion returns the currently deployed version of an app.
func getDeployedVersion(cl *dockerclient.Client, stackName string, recipeName string) (string, error) {
logrus.Debugf("Retrieve deployed version whether %s is already deployed", stackName)
log.Debugf("Retrieve deployed version whether %s is already deployed", stackName)
isDeployed, deployedVersion, err := stack.IsDeployed(context.Background(), cl, stackName)
if err != nil {
@ -285,7 +285,7 @@ func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName
}
if len(versions) == 0 {
logrus.Warnf("no published releases for %s in the recipe catalogue?", recipeName)
log.Warnf("no published releases for %s in the recipe catalogue?", recipeName)
return nil, nil
}
@ -311,7 +311,7 @@ func getAvailableUpgrades(cl *dockerclient.Client, stackName string, recipeName
}
}
logrus.Debugf("Available updates for %s: %s", stackName, availableUpgrades)
log.Debugf("Available updates for %s: %s", stackName, availableUpgrades)
return availableUpgrades, nil
}
@ -349,7 +349,7 @@ func mergeAbraShEnv(recipeName string, env envfile.AppEnv) error {
}
for k, v := range abraShEnv {
logrus.Debugf("read v:%s k: %s", v, k)
log.Debugf("read v:%s k: %s", v, k)
env[k] = v
}
@ -391,7 +391,7 @@ func createDeployConfig(recipeName string, stackName string, env envfile.AppEnv)
// tryUpgrade performs the upgrade if all the requirements are fulfilled.
func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
if recipeName == "" {
logrus.Debugf("don't update %s due to missing recipe name", stackName)
log.Debugf("don't update %s due to missing recipe name", stackName)
return nil
}
@ -401,7 +401,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
}
if chaos && !internal.Chaos {
logrus.Debugf("don't update %s due to chaos deployment", stackName)
log.Debugf("don't update %s due to chaos deployment", stackName)
return nil
}
@ -411,7 +411,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
}
if !updatesEnabled {
logrus.Debugf("don't update %s due to disabled auto updates or missing ENABLE_AUTO_UPDATE env", stackName)
log.Debugf("don't update %s due to disabled auto updates or missing ENABLE_AUTO_UPDATE env", stackName)
return nil
}
@ -421,7 +421,7 @@ func tryUpgrade(cl *dockerclient.Client, stackName, recipeName string) error {
}
if upgradeVersion == "" {
logrus.Debugf("don't update %s due to no new version", stackName)
log.Debugf("don't update %s due to no new version", stackName)
return nil
}
@ -458,7 +458,7 @@ func upgrade(cl *dockerclient.Client, stackName, recipeName,
return err
}
logrus.Infof("upgrade %s (%s) to version %s", stackName, recipeName, upgradeVersion)
log.Infof("upgrade %s (%s) to version %s", stackName, recipeName, upgradeVersion)
err = stack.RunDeploy(cl, deployOpts, compose, stackName, true)
@ -484,7 +484,7 @@ func newAbraApp(version, commit string) *cli.App {
}
app.Before = func(c *cli.Context) error {
logrus.Debugf("kadabra version %s, commit %s", version, commit)
log.Debugf("kadabra version %s, commit %s", version, commit)
return nil
}
@ -496,6 +496,6 @@ func RunApp(version, commit string) {
app := newAbraApp(version, commit)
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
log.Fatal(err)
}
}