From 24fdb1f60020109c71c696fdb47385d25e57adb1 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:26:04 -0300 Subject: [PATCH] fix(libstack): redirect the Docker and Compose logging to zerolog BE-11518 (#289) --- .golangci.yaml | 2 -- go.mod | 2 +- go.sum | 4 ---- pkg/libstack/compose/composeplugin.go | 8 +++++++- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 68872971a..648df24d1 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -20,8 +20,6 @@ linters-settings: deny: - pkg: 'encoding/json' desc: 'use github.com/segmentio/encoding/json' - - pkg: 'github.com/sirupsen/logrus' - desc: 'logging is allowed only by github.com/rs/zerolog' - pkg: 'golang.org/x/exp' desc: 'exp is not allowed' - pkg: 'github.com/portainer/libcrypto' diff --git a/go.mod b/go.mod index 078490071..cc34f23f2 100644 --- a/go.mod +++ b/go.mod @@ -42,6 +42,7 @@ require ( github.com/robfig/cron/v3 v3.0.1 github.com/rs/zerolog v1.29.0 github.com/segmentio/encoding v0.3.6 + github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.10.0 github.com/urfave/negroni v1.0.0 github.com/viney-shih/go-lock v1.1.1 @@ -207,7 +208,6 @@ require ( github.com/sergi/go-diff v1.3.1 // indirect github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b // indirect github.com/shibumi/go-pathspec v1.3.0 // indirect - github.com/sirupsen/logrus v1.9.3 // indirect github.com/skeema/knownhosts v1.2.1 // indirect github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect github.com/spf13/cobra v1.8.1 // indirect diff --git a/go.sum b/go.sum index 6376e9920..9a98a81e3 100644 --- a/go.sum +++ b/go.sum @@ -313,15 +313,11 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/csrf v1.7.1 h1:Ir3o2c1/Uzj6FBxMlAUB6SivgVMy1ONXwYgXn+/aHPE= -github.com/gorilla/csrf v1.7.1/go.mod h1:+a/4tCmqhG6/w4oafeAZ9pEa3/NZOWYVbD9fV0FwIQA= github.com/gorilla/csrf v1.7.2 h1:oTUjx0vyf2T+wkrx09Trsev1TE+/EbDAeHtSTbtC2eI= github.com/gorilla/csrf v1.7.2/go.mod h1:F1Fj3KG23WYHE6gozCmBAezKookxbIvUJT+121wTuLk= github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= -github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= diff --git a/pkg/libstack/compose/composeplugin.go b/pkg/libstack/compose/composeplugin.go index 24b8c5f3c..7b6a639c4 100644 --- a/pkg/libstack/compose/composeplugin.go +++ b/pkg/libstack/compose/composeplugin.go @@ -23,12 +23,18 @@ import ( "github.com/docker/compose/v2/pkg/compose" "github.com/docker/docker/registry" "github.com/rs/zerolog/log" + "github.com/sirupsen/logrus" ) const PortainerEdgeStackLabel = "io.portainer.edge_stack_id" var mu sync.Mutex +func init() { + // Redirect Compose logging to zerolog + logrus.SetOutput(log.Logger) +} + func withCli( ctx context.Context, options libstack.Options, @@ -36,7 +42,7 @@ func withCli( ) error { ctx = context.Background() - cli, err := command.NewDockerCli() + cli, err := command.NewDockerCli(command.WithCombinedStreams(log.Logger)) if err != nil { return fmt.Errorf("unable to create a Docker client: %w", err) }