forked from toolshed/abra
refactor: use central logger
This commit is contained in:
@ -17,11 +17,11 @@ import (
|
||||
"coopcloud.tech/abra/pkg/upstream/convert"
|
||||
"coopcloud.tech/abra/pkg/upstream/stack"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
loader "coopcloud.tech/abra/pkg/upstream/stack"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Get retrieves an app
|
||||
@ -36,7 +36,7 @@ func Get(appName string) (App, error) {
|
||||
return App{}, err
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved %s for %s", app, appName)
|
||||
log.Debugf("retrieved %s for %s", app, appName)
|
||||
|
||||
return app, nil
|
||||
}
|
||||
@ -125,7 +125,7 @@ func StackName(appName string) string {
|
||||
stackName := SanitiseAppName(appName)
|
||||
|
||||
if len(stackName) > config.MAX_SANITISED_APP_NAME_LENGTH {
|
||||
logrus.Debugf("trimming %s to %s to avoid runtime limits", stackName, stackName[:config.MAX_SANITISED_APP_NAME_LENGTH])
|
||||
log.Debugf("trimming %s to %s to avoid runtime limits", stackName, stackName[:config.MAX_SANITISED_APP_NAME_LENGTH])
|
||||
stackName = stackName[:config.MAX_SANITISED_APP_NAME_LENGTH]
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ func ReadAppEnvFile(appFile AppFile, name AppName) (App, error) {
|
||||
return App{}, fmt.Errorf("env file for %s couldn't be read: %s", name, err.Error())
|
||||
}
|
||||
|
||||
logrus.Debugf("read env %s from %s", env, appFile.Path)
|
||||
log.Debugf("read env %s from %s", env, appFile.Path)
|
||||
|
||||
app, err := NewApp(env, name, appFile)
|
||||
if err != nil {
|
||||
@ -281,7 +281,7 @@ func LoadAppFiles(servers ...string) (AppFiles, error) {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("collecting metadata from %v servers: %s", len(servers), strings.Join(servers, ", "))
|
||||
log.Debugf("collecting metadata from %v servers: %s", len(servers), strings.Join(servers, ", "))
|
||||
|
||||
for _, server := range servers {
|
||||
serverDir := path.Join(config.SERVERS_DIR, server)
|
||||
@ -387,7 +387,7 @@ func TemplateAppEnvSample(recipeName, appName, server, domain string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("copied & templated %s to %s", envSamplePath, appEnvPath)
|
||||
log.Debugf("copied & templated %s to %s", envSamplePath, appEnvPath)
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -472,7 +472,7 @@ func GetAppStatuses(apps []App, MachineReadable bool) (map[string]map[string]str
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved app statuses: %s", statuses)
|
||||
log.Debugf("retrieved app statuses: %s", statuses)
|
||||
|
||||
return statuses, nil
|
||||
}
|
||||
@ -486,7 +486,7 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv envfile.AppEnv
|
||||
return &composetypes.Config{}, err
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved %s for %s", compose.Filename, recipe)
|
||||
log.Debugf("retrieved %s for %s", compose.Filename, recipe)
|
||||
|
||||
return compose, nil
|
||||
}
|
||||
@ -495,13 +495,13 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv envfile.AppEnv
|
||||
func ExposeAllEnv(stackName string, compose *composetypes.Config, appEnv envfile.AppEnv) {
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
logrus.Debugf("Add the following environment to the app service config of %s:", stackName)
|
||||
log.Debugf("Add the following environment to the app service config of %s:", stackName)
|
||||
for k, v := range appEnv {
|
||||
_, exists := service.Environment[k]
|
||||
if !exists {
|
||||
value := v
|
||||
service.Environment[k] = &value
|
||||
logrus.Debugf("Add Key: %s Value: %s to %s", k, value, stackName)
|
||||
log.Debugf("Add Key: %s Value: %s to %s", k, value, stackName)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -570,9 +570,9 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
|
||||
}
|
||||
|
||||
if len(cmdNames) > 0 {
|
||||
logrus.Debugf("read %s from %s", strings.Join(cmdNames, " "), abraSh)
|
||||
log.Debugf("read %s from %s", strings.Join(cmdNames, " "), abraSh)
|
||||
} else {
|
||||
logrus.Debugf("read 0 command names from %s", abraSh)
|
||||
log.Debugf("read 0 command names from %s", abraSh)
|
||||
}
|
||||
|
||||
return cmdNames, nil
|
||||
|
@ -5,8 +5,8 @@ import (
|
||||
"strconv"
|
||||
|
||||
"coopcloud.tech/abra/pkg/envfile"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SetRecipeLabel adds the label 'coop-cloud.${STACK_NAME}.recipe=${RECIPE}' to the app container
|
||||
@ -14,7 +14,7 @@ import (
|
||||
func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe string) {
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
logrus.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName)
|
||||
log.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.recipe", stackName)
|
||||
service.Deploy.Labels[labelKey] = recipe
|
||||
}
|
||||
@ -26,7 +26,7 @@ func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe strin
|
||||
func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
logrus.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName)
|
||||
log.Debugf("set label 'coop-cloud.%s.chaos' to %v for %s", stackName, chaos, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName)
|
||||
service.Deploy.Labels[labelKey] = strconv.FormatBool(chaos)
|
||||
}
|
||||
@ -37,7 +37,7 @@ func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
|
||||
func SetChaosVersionLabel(compose *composetypes.Config, stackName string, chaosVersion string) {
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
logrus.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName)
|
||||
log.Debugf("set label 'coop-cloud.%s.chaos-version' to %v for %s", stackName, chaosVersion, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.chaos-version", stackName)
|
||||
service.Deploy.Labels[labelKey] = chaosVersion
|
||||
}
|
||||
@ -54,7 +54,7 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv envfi
|
||||
if !exists {
|
||||
enable_auto_update = "false"
|
||||
}
|
||||
logrus.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName)
|
||||
log.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName)
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName)
|
||||
service.Deploy.Labels[labelKey] = enable_auto_update
|
||||
}
|
||||
@ -66,13 +66,13 @@ func GetLabel(compose *composetypes.Config, stackName string, label string) stri
|
||||
for _, service := range compose.Services {
|
||||
if service.Name == "app" {
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.%s", stackName, label)
|
||||
logrus.Debugf("get label '%s'", labelKey)
|
||||
log.Debugf("get label '%s'", labelKey)
|
||||
if labelValue, ok := service.Deploy.Labels[labelKey]; ok {
|
||||
return labelValue
|
||||
}
|
||||
}
|
||||
}
|
||||
logrus.Debugf("no %s label found for %s", label, stackName)
|
||||
log.Debugf("no %s label found for %s", label, stackName)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ func GetTimeoutFromLabel(compose *composetypes.Config, stackName string) (int, e
|
||||
timeout := 50 // Default Timeout
|
||||
var err error = nil
|
||||
if timeoutLabel := GetLabel(compose, stackName, "timeout"); timeoutLabel != "" {
|
||||
logrus.Debugf("timeout label: %s", timeoutLabel)
|
||||
log.Debugf("timeout label: %s", timeoutLabel)
|
||||
timeout, err = strconv.Atoi(timeoutLabel)
|
||||
}
|
||||
return timeout, err
|
||||
|
Reference in New Issue
Block a user