forked from toolshed/abra
refactor: use central logger
This commit is contained in:
@ -27,8 +27,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
)
|
||||
|
||||
@ -46,7 +46,7 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
|
||||
)
|
||||
c.cmd = exec.CommandContext(ctx, cmd, args...)
|
||||
// we assume that args never contains sensitive information
|
||||
logrus.Debugf("commandconn: starting %s with %v", cmd, args)
|
||||
log.Debugf("commandconn: starting %s with %v", cmd, args)
|
||||
c.cmd.Env = os.Environ()
|
||||
c.cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
setPdeathsig(c.cmd)
|
||||
@ -189,14 +189,14 @@ func (c *commandConn) CloseRead() error {
|
||||
// NOTE: maybe already closed here
|
||||
if err := c.stdout.Close(); err != nil && !ignorableCloseError(err) {
|
||||
// muted because https://github.com/docker/compose/issues/8544
|
||||
// logrus.Warnf("commandConn.CloseRead: %v", err)
|
||||
// log.Warnf("commandConn.CloseRead: %v", err)
|
||||
}
|
||||
c.stdioClosedMu.Lock()
|
||||
c.stdoutClosed = true
|
||||
c.stdioClosedMu.Unlock()
|
||||
if err := c.killIfStdioClosed(); err != nil {
|
||||
// muted because https://github.com/docker/compose/issues/8544
|
||||
// logrus.Warnf("commandConn.CloseRead: %v", err)
|
||||
// log.Warnf("commandConn.CloseRead: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -213,14 +213,14 @@ func (c *commandConn) CloseWrite() error {
|
||||
// NOTE: maybe already closed here
|
||||
if err := c.stdin.Close(); err != nil && !ignorableCloseError(err) {
|
||||
// muted because https://github.com/docker/compose/issues/8544
|
||||
// logrus.Warnf("commandConn.CloseWrite: %v", err)
|
||||
// log.Warnf("commandConn.CloseWrite: %v", err)
|
||||
}
|
||||
c.stdioClosedMu.Lock()
|
||||
c.stdinClosed = true
|
||||
c.stdioClosedMu.Unlock()
|
||||
if err := c.killIfStdioClosed(); err != nil {
|
||||
// muted because https://github.com/docker/compose/issues/8544
|
||||
// logrus.Warnf("commandConn.CloseWrite: %v", err)
|
||||
// log.Warnf("commandConn.CloseWrite: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -236,11 +236,11 @@ func (c *commandConn) Write(p []byte) (int, error) {
|
||||
func (c *commandConn) Close() error {
|
||||
var err error
|
||||
if err = c.CloseRead(); err != nil {
|
||||
logrus.Warnf("commandConn.Close: CloseRead: %v", err)
|
||||
log.Warnf("commandConn.Close: CloseRead: %v", err)
|
||||
}
|
||||
if err = c.CloseWrite(); err != nil {
|
||||
// muted because https://github.com/docker/compose/issues/8544
|
||||
// logrus.Warnf("commandConn.Close: CloseWrite: %v", err)
|
||||
// log.Warnf("commandConn.Close: CloseWrite: %v", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -252,15 +252,15 @@ func (c *commandConn) RemoteAddr() net.Addr {
|
||||
return c.remoteAddr
|
||||
}
|
||||
func (c *commandConn) SetDeadline(t time.Time) error {
|
||||
logrus.Debugf("unimplemented call: SetDeadline(%v)", t)
|
||||
log.Debugf("unimplemented call: SetDeadline(%v)", t)
|
||||
return nil
|
||||
}
|
||||
func (c *commandConn) SetReadDeadline(t time.Time) error {
|
||||
logrus.Debugf("unimplemented call: SetReadDeadline(%v)", t)
|
||||
log.Debugf("unimplemented call: SetReadDeadline(%v)", t)
|
||||
return nil
|
||||
}
|
||||
func (c *commandConn) SetWriteDeadline(t time.Time) error {
|
||||
logrus.Debugf("unimplemented call: SetWriteDeadline(%v)", t)
|
||||
log.Debugf("unimplemented call: SetWriteDeadline(%v)", t)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ type stderrWriter struct {
|
||||
}
|
||||
|
||||
func (w *stderrWriter) Write(p []byte) (int, error) {
|
||||
logrus.Debugf("%s%s", w.debugPrefix, string(p))
|
||||
log.Debugf("%s%s", w.debugPrefix, string(p))
|
||||
w.stderrMu.Lock()
|
||||
if w.stderr.Len() > 4096 {
|
||||
w.stderr.Reset()
|
||||
|
@ -6,11 +6,11 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types"
|
||||
apiclient "github.com/docker/docker/client"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RunExec runs a command on a remote container. io.Writer corresponds to the
|
||||
@ -109,7 +109,7 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclie
|
||||
}
|
||||
|
||||
if err := <-errCh; err != nil {
|
||||
logrus.Debugf("Error hijack: %s", err)
|
||||
log.Debugf("Error hijack: %s", err)
|
||||
return out, err
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/moby/term"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// The default escape key sequence: ctrl-p, ctrl-q
|
||||
@ -96,7 +96,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
|
||||
if h.detachKeys != "" {
|
||||
customEscapeKeys, err := term.ToBytes(h.detachKeys)
|
||||
if err != nil {
|
||||
logrus.Warnf("invalid detach escape keys, using default: %s", err)
|
||||
log.Warnf("invalid detach escape keys, using default: %s", err)
|
||||
} else {
|
||||
escapeKeys = customEscapeKeys
|
||||
}
|
||||
@ -128,10 +128,10 @@ func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
|
||||
_, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader)
|
||||
}
|
||||
|
||||
logrus.Debug("[hijack] End of stdout")
|
||||
log.Debug("[hijack] End of stdout")
|
||||
|
||||
if err != nil {
|
||||
logrus.Debugf("Error receiveStdout: %s", err)
|
||||
log.Debugf("Error receiveStdout: %s", err)
|
||||
}
|
||||
|
||||
outputDone <- err
|
||||
@ -152,7 +152,7 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
|
||||
// messages will be in normal type.
|
||||
restoreInput()
|
||||
|
||||
logrus.Debug("[hijack] End of stdin")
|
||||
log.Debug("[hijack] End of stdin")
|
||||
|
||||
if _, ok := err.(term.EscapeError); ok {
|
||||
detached <- err
|
||||
@ -163,12 +163,12 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
|
||||
// This error will also occur on the receive
|
||||
// side (from stdout) where it will be
|
||||
// propagated back to the caller.
|
||||
logrus.Debugf("Error sendStdin: %s", err)
|
||||
log.Debugf("Error sendStdin: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := h.resp.CloseWrite(); err != nil {
|
||||
logrus.Debugf("Couldn't send EOF: %s", err)
|
||||
log.Debugf("Couldn't send EOF: %s", err)
|
||||
}
|
||||
|
||||
close(inputDone)
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/client"
|
||||
apiclient "github.com/docker/docker/client"
|
||||
"github.com/moby/sys/signal"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// resizeTtyTo resizes tty to specific height and width
|
||||
@ -35,7 +35,7 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
logrus.Debugf("Error resize: %s\r", err)
|
||||
log.Debugf("Error resize: %s\r", err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RunServiceScale scales a service (useful for restart action)
|
||||
@ -37,7 +37,7 @@ func RunServiceScale(ctx context.Context, cl *client.Client, serviceID string, s
|
||||
}
|
||||
|
||||
for _, warning := range response.Warnings {
|
||||
logrus.Warn(warning)
|
||||
log.Warn(warning)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -7,10 +7,10 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/docker/cli/cli/compose/loader"
|
||||
"github.com/docker/cli/cli/compose/schema"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// DontSkipValidation ensures validation is done for compose file loading
|
||||
@ -51,13 +51,13 @@ func LoadComposefile(opts Deploy, appEnv map[string]string, options ...func(*loa
|
||||
|
||||
unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
|
||||
if len(unsupportedProperties) > 0 {
|
||||
logrus.Warnf("%s: ignoring unsupported options: %s",
|
||||
log.Warnf("%s: ignoring unsupported options: %s",
|
||||
recipeName, strings.Join(unsupportedProperties, ", "))
|
||||
}
|
||||
|
||||
deprecatedProperties := loader.GetDeprecatedProperties(dicts...)
|
||||
if len(deprecatedProperties) > 0 {
|
||||
logrus.Warnf("%s: ignoring deprecated options: %s",
|
||||
log.Warnf("%s: ignoring deprecated options: %s",
|
||||
recipeName, propertyWarnings(deprecatedProperties))
|
||||
}
|
||||
return config, nil
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/client"
|
||||
apiclient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RunRemove is the swarm implementation of docker stack remove
|
||||
@ -46,7 +46,7 @@ func RunRemove(ctx context.Context, client *apiclient.Client, opts Remove) error
|
||||
}
|
||||
|
||||
if len(services)+len(networks)+len(secrets)+len(configs) == 0 {
|
||||
logrus.Warning(fmt.Errorf("nothing found in stack: %s", namespace))
|
||||
log.Warnf("nothing found in stack: %s", namespace)
|
||||
continue
|
||||
}
|
||||
|
||||
@ -87,10 +87,10 @@ func removeServices(
|
||||
var hasError bool
|
||||
sort.Slice(services, sortServiceByName(services))
|
||||
for _, service := range services {
|
||||
logrus.Infof("removing service %s\n", service.Spec.Name)
|
||||
log.Infof("removing service %s\n", service.Spec.Name)
|
||||
if err := client.ServiceRemove(ctx, service.ID); err != nil {
|
||||
hasError = true
|
||||
logrus.Fatalf("failed to remove service %s: %s", service.ID, err)
|
||||
log.Fatalf("failed to remove service %s: %s", service.ID, err)
|
||||
}
|
||||
}
|
||||
return hasError
|
||||
@ -103,10 +103,10 @@ func removeNetworks(
|
||||
) bool {
|
||||
var hasError bool
|
||||
for _, network := range networks {
|
||||
logrus.Infof("removing network %s\n", network.Name)
|
||||
log.Infof("removing network %s\n", network.Name)
|
||||
if err := client.NetworkRemove(ctx, network.ID); err != nil {
|
||||
hasError = true
|
||||
logrus.Fatalf("failed to remove network %s: %s", network.ID, err)
|
||||
log.Fatalf("failed to remove network %s: %s", network.ID, err)
|
||||
}
|
||||
}
|
||||
return hasError
|
||||
@ -119,10 +119,10 @@ func removeSecrets(
|
||||
) bool {
|
||||
var hasError bool
|
||||
for _, secret := range secrets {
|
||||
logrus.Infof("Removing secret %s\n", secret.Spec.Name)
|
||||
log.Infof("Removing secret %s\n", secret.Spec.Name)
|
||||
if err := client.SecretRemove(ctx, secret.ID); err != nil {
|
||||
hasError = true
|
||||
logrus.Fatalf("Failed to remove secret %s: %s", secret.ID, err)
|
||||
log.Fatalf("Failed to remove secret %s: %s", secret.ID, err)
|
||||
}
|
||||
}
|
||||
return hasError
|
||||
@ -135,10 +135,10 @@ func removeConfigs(
|
||||
) bool {
|
||||
var hasError bool
|
||||
for _, config := range configs {
|
||||
logrus.Infof("removing config %s\n", config.Spec.Name)
|
||||
log.Infof("removing config %s\n", config.Spec.Name)
|
||||
if err := client.ConfigRemove(ctx, config.ID); err != nil {
|
||||
hasError = true
|
||||
logrus.Fatalf("failed to remove config %s: %s", config.ID, err)
|
||||
log.Fatalf("failed to remove config %s: %s", config.ID, err)
|
||||
}
|
||||
}
|
||||
return hasError
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
stdlibErr "errors"
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/upstream/convert"
|
||||
"github.com/docker/cli/cli/command/service/progress"
|
||||
"github.com/docker/cli/cli/command/stack/formatter"
|
||||
@ -23,7 +24,6 @@ import (
|
||||
"github.com/docker/docker/client"
|
||||
dockerClient "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Resolve image constants
|
||||
@ -118,12 +118,12 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("%s has been detected as deployed with version %s", stackName, version)
|
||||
log.Debugf("%s has been detected as deployed with version %s", stackName, version)
|
||||
|
||||
return true, version, nil
|
||||
}
|
||||
|
||||
logrus.Debugf("%s has been detected as not deployed", stackName)
|
||||
log.Debugf("%s has been detected as not deployed", stackName)
|
||||
return isDeployed, version, nil
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ func IsDeployed(ctx context.Context, cl *dockerClient.Client, stackName string)
|
||||
func pruneServices(ctx context.Context, cl *dockerClient.Client, namespace convert.Namespace, services map[string]struct{}) {
|
||||
oldServices, err := GetStackServices(ctx, cl, namespace.Name())
|
||||
if err != nil {
|
||||
logrus.Infof("failed to list services: %s\n", err)
|
||||
log.Infof("failed to list services: %s\n", err)
|
||||
}
|
||||
|
||||
pruneServices := []swarm.Service{}
|
||||
@ -213,9 +213,9 @@ func deployCompose(ctx context.Context, cl *dockerClient.Client, opts Deploy, co
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Infof("waiting for %s to deploy... please hold 🤚", appName)
|
||||
log.Infof("waiting for %s to deploy... please hold 🤚", appName)
|
||||
if err := waitOnServices(ctx, cl, serviceIDs, appName); err == nil {
|
||||
logrus.Infof("Successfully deployed %s", appName)
|
||||
log.Infof("Successfully deployed %s", appName)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -265,7 +265,7 @@ func createSecrets(ctx context.Context, cl *dockerClient.Client, secrets []swarm
|
||||
}
|
||||
case dockerClient.IsErrNotFound(err):
|
||||
// secret does not exist, then we create a new one.
|
||||
logrus.Infof("Creating secret %s\n", secretSpec.Name)
|
||||
log.Infof("Creating secret %s\n", secretSpec.Name)
|
||||
if _, err := cl.SecretCreate(ctx, secretSpec); err != nil {
|
||||
return errors.Wrapf(err, "failed to create secret %s", secretSpec.Name)
|
||||
}
|
||||
@ -287,7 +287,7 @@ func createConfigs(ctx context.Context, cl *dockerClient.Client, configs []swarm
|
||||
}
|
||||
case dockerClient.IsErrNotFound(err):
|
||||
// config does not exist, then we create a new one.
|
||||
logrus.Infof("creating config %s\n", configSpec.Name)
|
||||
log.Infof("creating config %s\n", configSpec.Name)
|
||||
if _, err := cl.ConfigCreate(ctx, configSpec); err != nil {
|
||||
return errors.Wrapf(err, "failed to create config %s", configSpec.Name)
|
||||
}
|
||||
@ -318,7 +318,7 @@ func createNetworks(ctx context.Context, cl *dockerClient.Client, namespace conv
|
||||
createOpts.Driver = defaultNetworkDriver
|
||||
}
|
||||
|
||||
logrus.Infof("creating network %s\n", name)
|
||||
log.Infof("creating network %s\n", name)
|
||||
if _, err := cl.NetworkCreate(ctx, name, createOpts); err != nil {
|
||||
return errors.Wrapf(err, "failed to create network %s", name)
|
||||
}
|
||||
@ -355,7 +355,7 @@ func deployServices(
|
||||
)
|
||||
|
||||
if service, exists := existingServiceMap[name]; exists {
|
||||
logrus.Infof("Updating service %s (id: %s)\n", name, service.ID)
|
||||
log.Infof("Updating service %s (id: %s)\n", name, service.ID)
|
||||
|
||||
updateOpts := types.ServiceUpdateOptions{EncodedRegistryAuth: encodedAuth}
|
||||
|
||||
@ -394,12 +394,12 @@ func deployServices(
|
||||
}
|
||||
|
||||
for _, warning := range response.Warnings {
|
||||
logrus.Warn(warning)
|
||||
log.Warn(warning)
|
||||
}
|
||||
|
||||
serviceIDs = append(serviceIDs, service.ID)
|
||||
} else {
|
||||
logrus.Infof("creating service %s\n", name)
|
||||
log.Infof("creating service %s\n", name)
|
||||
|
||||
createOpts := types.ServiceCreateOptions{EncodedRegistryAuth: encodedAuth}
|
||||
|
||||
@ -418,7 +418,7 @@ func deployServices(
|
||||
}
|
||||
|
||||
if dontWait {
|
||||
logrus.Warn("skipping converge logic checks")
|
||||
log.Warn("skipping converge logic checks")
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user