Skip to content

Commit

Permalink
fix upgrade connection
Browse files Browse the repository at this point in the history
add more debuging log
  • Loading branch information
pleclech committed May 30, 2023
1 parent de6002f commit 032543e
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 155 deletions.
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module github.com/pleclech/portainerproxy

go 1.19
go 1.20

require github.com/sirupsen/logrus v1.9.2
require go.uber.org/zap v1.24.0

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
)
21 changes: 12 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.2 h1:oxx1eChJGI6Uks2ZC4W1zpLlVgqB8ner4EuQwV4Ik1Y=
github.com/sirupsen/logrus v1.9.2/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
43 changes: 27 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"time"

"github.com/pleclech/portainerproxy/pkg/portainer"
log "github.com/sirupsen/logrus"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -66,15 +66,24 @@ func main() {
return
}

var logger *zap.Logger

// Enable debug mode if the debug flag is provided
if *debugFlag {
log.SetLevel(log.DebugLevel)
// set debug mode for zap
logger, _ = zap.NewDevelopment()
// log.SetLevel(log.DebugLevel)
} else {
logger, _ = zap.NewProduction()
}

defer logger.Sync()

// split address into host and port
host, port, err := net.SplitHostPort(*address)
if err != nil {
log.Fatal(err)
logger.Fatal("Invalid address", zap.Error(err))
// log.Fatal(err)
}

// if host is empty, set it to localhost
Expand All @@ -84,9 +93,9 @@ func main() {

*address = host + ":" + port

proxy, err := portainer.NewProxy(*portainerURL, *dockerHost, *address, *portainerServiceName)
proxy, err := portainer.NewProxy(logger, *portainerURL, *dockerHost, *address, *portainerServiceName)
if err != nil {
log.Fatal(err)
logger.Fatal(err.Error())
}

// Create an HTTP server
Expand All @@ -97,26 +106,28 @@ func main() {

// Start the HTTP/HTTPS server based on the flag
go func() {
log.Infof("Starting proxy server...")
log.Infof("Version: %s", version)
log.Infof("Portainer URL: %s", *portainerURL)
log.Infof("Docker host: %s", *dockerHost)
log.Infof("Debug mode: %v", *debugFlag)
logger.Info("Starting proxy server...",
zap.String("version", version),
zap.String("Portainer url", *portainerURL),
zap.String("Docker host", *dockerHost),
zap.Bool("debug", *debugFlag))

logger.Sync()

var err error
if *useHTTPS {
if *certFile == "" || *keyFile == "" {
log.Fatal("Both certificate file and key file paths must be provided for HTTPS mode")
logger.Fatal("Both certificate file and key file paths must be provided for HTTPS mode")
}

log.Infof("HTTPS proxy server listening on %v\n", *address)
logger.Info("HTTPS proxy server listening on", zap.String("address", *address))
err = server.ListenAndServeTLS(*certFile, *keyFile)
} else {
log.Infof("HTTP proxy server listening on %v", *address)
logger.Info("HTTP proxy server listening on", zap.String("address", *address))
err = server.ListenAndServe()
}
if err != nil && err != http.ErrServerClosed {
log.Fatal(err)
logger.Fatal(err.Error())
}
}()

Expand All @@ -132,9 +143,9 @@ func main() {

// Attempt to gracefully shut down the server
if err := server.Shutdown(ctx); err != nil {
log.Fatalf("Server shutdown error: %s", err)
logger.Fatal("Server shutdown error", zap.Error(err))
}

// and then shutdown the server
log.Infof("Shutting down the server...")
logger.Info("Shutting down the server...")
}
Loading

0 comments on commit 032543e

Please sign in to comment.