forked from toolshed/abra
refactor: use central logger
This commit is contained in:
@ -5,13 +5,13 @@ import (
|
||||
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/service"
|
||||
"coopcloud.tech/abra/pkg/upstream/container"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RetrieveBackupBotContainer gets the deployed backupbot container.
|
||||
@ -22,7 +22,7 @@ func RetrieveBackupBotContainer(cl *dockerClient.Client) (types.Container, error
|
||||
return types.Container{}, err
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved %s as backup enabled service", chosenService.Spec.Name)
|
||||
log.Debugf("retrieved %s as backup enabled service", chosenService.Spec.Name)
|
||||
|
||||
filters := filters.NewArgs()
|
||||
filters.Add("name", chosenService.Spec.Name)
|
||||
@ -51,7 +51,7 @@ func RunBackupCmdRemote(cl *dockerClient.Client, backupCmd string, containerID s
|
||||
Tty: true,
|
||||
}
|
||||
|
||||
logrus.Debugf("running backup %s on %s with exec config %v", backupCmd, containerID, execBackupListOpts)
|
||||
log.Debugf("running backup %s on %s with exec config %v", backupCmd, containerID, execBackupListOpts)
|
||||
|
||||
// FIXME: avoid instantiating a new CLI
|
||||
dcli, err := command.NewDockerCli()
|
||||
|
@ -3,8 +3,7 @@ package internal
|
||||
import (
|
||||
"os"
|
||||
|
||||
logrusStack "github.com/Gurpartap/logrus-stack"
|
||||
"github.com/sirupsen/logrus"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -288,10 +287,8 @@ var AllServicesFlag = &cli.BoolFlag{
|
||||
// SubCommandBefore wires up pre-action machinery (e.g. --debug handling).
|
||||
func SubCommandBefore(c *cli.Context) error {
|
||||
if Debug {
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
logrus.SetFormatter(&logrus.TextFormatter{})
|
||||
logrus.SetOutput(os.Stderr)
|
||||
logrus.AddHook(logrusStack.StandardHook())
|
||||
log.SetLevel(log.DebugLevel)
|
||||
log.SetOutput(os.Stderr)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -11,13 +11,13 @@ import (
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
containerPkg "coopcloud.tech/abra/pkg/container"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/upstream/container"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RunCmdRemote executes an abra.sh command in the target service
|
||||
@ -30,7 +30,7 @@ func RunCmdRemote(cl *dockerClient.Client, app appPkg.App, abraSh, serviceName,
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("retrieved %s as target container on %s", formatter.ShortenID(targetContainer.ID), app.Server)
|
||||
log.Debugf("retrieved %s as target container on %s", formatter.ShortenID(targetContainer.ID), app.Server)
|
||||
|
||||
toTarOpts := &archive.TarOptions{NoOverwriteDirNonDir: true, Compression: archive.Gzip}
|
||||
content, err := archive.TarWithOptions(abraSh, toTarOpts)
|
||||
@ -61,7 +61,7 @@ func RunCmdRemote(cl *dockerClient.Client, app appPkg.App, abraSh, serviceName,
|
||||
}
|
||||
|
||||
if _, err := container.RunExec(dcli, cl, targetContainer.ID, &execCreateOpts); err != nil {
|
||||
logrus.Infof("%s does not exist for %s, use /bin/sh as fallback", shell, app.Name)
|
||||
log.Infof("%s does not exist for %s, use /bin/sh as fallback", shell, app.Name)
|
||||
shell = "/bin/sh"
|
||||
}
|
||||
|
||||
@ -72,10 +72,10 @@ func RunCmdRemote(cl *dockerClient.Client, app appPkg.App, abraSh, serviceName,
|
||||
cmd = []string{shell, "-c", fmt.Sprintf("TARGET=%s; APP_NAME=%s; STACK_NAME=%s; . /tmp/abra.sh; %s", serviceName, app.Name, app.StackName(), cmdName)}
|
||||
}
|
||||
|
||||
logrus.Debugf("running command: %s", strings.Join(cmd, " "))
|
||||
log.Debugf("running command: %s", strings.Join(cmd, " "))
|
||||
|
||||
if RemoteUser != "" {
|
||||
logrus.Debugf("running command with user %s", RemoteUser)
|
||||
log.Debugf("running command with user %s", RemoteUser)
|
||||
execCreateOpts.User = RemoteUser
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,9 @@ import (
|
||||
appPkg "coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// NewVersionOverview shows an upgrade or downgrade overview
|
||||
@ -37,7 +37,7 @@ func NewVersionOverview(app appPkg.App, currentVersion, newVersion, releaseNotes
|
||||
fmt.Println()
|
||||
fmt.Print(releaseNotes)
|
||||
} else {
|
||||
logrus.Warnf("no release notes available for %s", newVersion)
|
||||
log.Warnf("no release notes available for %s", newVersion)
|
||||
}
|
||||
|
||||
if NoInput {
|
||||
@ -54,7 +54,7 @@ func NewVersionOverview(app appPkg.App, currentVersion, newVersion, releaseNotes
|
||||
}
|
||||
|
||||
if !response {
|
||||
logrus.Fatal("exiting as requested")
|
||||
log.Fatal("exiting as requested")
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -103,7 +103,7 @@ func PostCmds(cl *dockerClient.Client, app appPkg.App, commands string) error {
|
||||
if len(commandParts) > 2 {
|
||||
parsedCmdArgs = fmt.Sprintf("%s ", strings.Join(commandParts[2:], " "))
|
||||
}
|
||||
logrus.Infof("running post-command '%s %s' in container %s", cmdName, parsedCmdArgs, targetServiceName)
|
||||
log.Infof("running post-command '%s %s' in container %s", cmdName, parsedCmdArgs, targetServiceName)
|
||||
|
||||
if err := EnsureCommand(abraSh, app.Recipe, cmdName); err != nil {
|
||||
return err
|
||||
@ -125,7 +125,7 @@ func PostCmds(cl *dockerClient.Client, app appPkg.App, commands string) error {
|
||||
return fmt.Errorf(fmt.Sprintf("no service %s for %s?", targetServiceName, app.Name))
|
||||
}
|
||||
|
||||
logrus.Debugf("running command %s %s within the context of %s_%s", cmdName, parsedCmdArgs, app.StackName(), targetServiceName)
|
||||
log.Debugf("running command %s %s within the context of %s_%s", cmdName, parsedCmdArgs, app.StackName(), targetServiceName)
|
||||
|
||||
Tty = true
|
||||
if err := RunCmdRemote(cl, app, abraSh, targetServiceName, cmdName, parsedCmdArgs); err != nil {
|
||||
@ -167,7 +167,7 @@ func DeployOverview(app appPkg.App, version, message string) error {
|
||||
}
|
||||
|
||||
if !response {
|
||||
logrus.Fatal("exiting as requested")
|
||||
log.Fatal("exiting as requested")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -3,7 +3,7 @@ package internal
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -11,8 +11,8 @@ import (
|
||||
// terminal, and shows the help command.
|
||||
func ShowSubcommandHelpAndError(c *cli.Context, err interface{}) {
|
||||
if err2 := cli.ShowSubcommandHelp(c); err2 != nil {
|
||||
logrus.Error(err2)
|
||||
log.Error(err2)
|
||||
}
|
||||
logrus.Error(err)
|
||||
log.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ import (
|
||||
"fmt"
|
||||
|
||||
"coopcloud.tech/abra/pkg/formatter"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/distribution/reference"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// PromptBumpType prompts for version bump type
|
||||
@ -65,7 +65,7 @@ func GetBumpType() string {
|
||||
} else if Patch {
|
||||
bumpType = "patch"
|
||||
} else {
|
||||
logrus.Fatal("no version bump type specififed?")
|
||||
log.Fatal("no version bump type specififed?")
|
||||
}
|
||||
|
||||
return bumpType
|
||||
@ -80,7 +80,7 @@ func SetBumpType(bumpType string) {
|
||||
} else if bumpType == "patch" {
|
||||
Patch = true
|
||||
} else {
|
||||
logrus.Fatal("no version bump type specififed?")
|
||||
log.Fatal("no version bump type specififed?")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,9 +6,9 @@ import (
|
||||
|
||||
"coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -21,7 +21,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
|
||||
catl, err := recipe.ReadRecipeCatalogue(Offline)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
knownRecipes := make(map[string]bool)
|
||||
@ -31,7 +31,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
|
||||
localRecipes, err := recipe.GetRecipesLocal()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, recipeLocal := range localRecipes {
|
||||
@ -49,7 +49,7 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
Options: recipes,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &recipeName); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,18 +61,18 @@ func ValidateRecipe(c *cli.Context) recipe.Recipe {
|
||||
if err != nil {
|
||||
if c.Command.Name == "generate" {
|
||||
if strings.Contains(err.Error(), "missing a compose") {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
logrus.Warn(err)
|
||||
log.Warn(err)
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "template_driver is not allowed") {
|
||||
logrus.Warnf("ensure %s recipe compose.* files include \"version: '3.8'\"", recipeName)
|
||||
log.Warnf("ensure %s recipe compose.* files include \"version: '3.8'\"", recipeName)
|
||||
}
|
||||
logrus.Fatalf("unable to validate recipe: %s", err)
|
||||
log.Fatalf("unable to validate recipe: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("validated %s as recipe argument", recipeName)
|
||||
log.Debugf("validated %s as recipe argument", recipeName)
|
||||
|
||||
return chosenRecipe
|
||||
}
|
||||
@ -87,10 +87,10 @@ func ValidateApp(c *cli.Context) app.App {
|
||||
|
||||
app, err := app.Get(appName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Debugf("validated %s as app argument", appName)
|
||||
log.Debugf("validated %s as app argument", appName)
|
||||
|
||||
return app
|
||||
}
|
||||
@ -105,7 +105,7 @@ func ValidateDomain(c *cli.Context) string {
|
||||
Default: "example.com",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &domainName); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ func ValidateDomain(c *cli.Context) string {
|
||||
ShowSubcommandHelpAndError(c, errors.New("no domain provided"))
|
||||
}
|
||||
|
||||
logrus.Debugf("validated %s as domain argument", domainName)
|
||||
log.Debugf("validated %s as domain argument", domainName)
|
||||
|
||||
return domainName
|
||||
}
|
||||
@ -138,7 +138,7 @@ func ValidateServer(c *cli.Context) string {
|
||||
|
||||
serverNames, err := config.ReadServerNames()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if serverName == "" && !NoInput {
|
||||
@ -147,7 +147,7 @@ func ValidateServer(c *cli.Context) string {
|
||||
Options: serverNames,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &serverName); err != nil {
|
||||
logrus.Fatal(err)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ func ValidateServer(c *cli.Context) string {
|
||||
ShowSubcommandHelpAndError(c, errors.New("server doesn't exist?"))
|
||||
}
|
||||
|
||||
logrus.Debugf("validated %s as server argument", serverName)
|
||||
log.Debugf("validated %s as server argument", serverName)
|
||||
|
||||
return serverName
|
||||
}
|
||||
|
Reference in New Issue
Block a user