From 3dfbd3a439867d769f49bd4d337edc64384e942e Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 13 Oct 2023 05:13:49 +0000 Subject: [PATCH 1/5] fix transport setup keys missing on dmsg-monitor and network-monitor reading config --- pkg/dmsg-monitor/api/api.go | 1 + pkg/network-monitor/api/api.go | 1 + 2 files changed, 2 insertions(+) diff --git a/pkg/dmsg-monitor/api/api.go b/pkg/dmsg-monitor/api/api.go index 31261936..9a50196d 100644 --- a/pkg/dmsg-monitor/api/api.go +++ b/pkg/dmsg-monitor/api/api.go @@ -401,6 +401,7 @@ func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 { conf.Launcher.BinPath = oldConf.Launcher.BinPath conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr conf.CLIAddr = oldConf.CLIAddr + conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs // following services are not needed conf.STCP = nil diff --git a/pkg/network-monitor/api/api.go b/pkg/network-monitor/api/api.go index 0b32b8a6..f337fa26 100644 --- a/pkg/network-monitor/api/api.go +++ b/pkg/network-monitor/api/api.go @@ -567,6 +567,7 @@ func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 { conf.Launcher.BinPath = oldConf.Launcher.BinPath conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr conf.CLIAddr = oldConf.CLIAddr + conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs // following services are not needed conf.STCP = nil From 22fc18df5eaa667f09a0a90f77bda7e921ce5d00 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 13 Oct 2023 05:14:29 +0000 Subject: [PATCH 2/5] change reading config logic of vpn-monitor and public-visor-monitor --- cmd/public-visor-monitor/commands/root.go | 30 +---------- cmd/vpn-monitor/commands/root.go | 30 +---------- pkg/public-visor-monitor/api/api.go | 63 +++++++++++++++++++++++ pkg/vpn-monitor/api/api.go | 62 ++++++++++++++++++++++ 4 files changed, 127 insertions(+), 58 deletions(-) diff --git a/cmd/public-visor-monitor/commands/root.go b/cmd/public-visor-monitor/commands/root.go index adc238cd..ad85043e 100644 --- a/cmd/public-visor-monitor/commands/root.go +++ b/cmd/public-visor-monitor/commands/root.go @@ -2,12 +2,9 @@ package commands import ( - "bytes" "context" - "io" "log" "os" - "path/filepath" "time" cc "github.com/ivanpirog/coloredcobra" @@ -16,7 +13,6 @@ import ( "github.com/skycoin/skywire-utilities/pkg/cmdutil" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/skycoin/skywire-utilities/pkg/tcpproxy" - "github.com/skycoin/skywire/pkg/visor/visorconfig" "github.com/spf13/cobra" "github.com/skycoin/skywire-services/pkg/public-visor-monitor/api" @@ -70,7 +66,7 @@ var RootCmd = &cobra.Command{ logging.SetLevel(lvl) - conf := initConfig(confPath, visorBuildInfo, mLogger) + conf := api.InitConfig(confPath, mLogger) srvURLs := api.ServicesURLs{ SD: conf.Launcher.ServiceDisc, @@ -110,30 +106,6 @@ var RootCmd = &cobra.Command{ }, } -func initConfig(confPath string, visorBuildInfo *buildinfo.Info, mLog *logging.MasterLogger) *visorconfig.V1 { - log := mLog.PackageLogger("public_visor_monitor:config") - var r io.Reader - - if confPath != "" { - log.WithField("filepath", confPath).Info() - f, err := os.ReadFile(filepath.Clean(confPath)) - if err != nil { - log.WithError(err).Fatal("Failed to read config file.") - } - r = bytes.NewReader(f) - } - - conf, compat, err := visorconfig.Parse(log, r, confPath, visorBuildInfo) - if err != nil { - log.WithError(err).Fatal("Failed to read in config.") - } - if !compat { - log.Fatalf("failed to start skywire - config version is incompatible") - } - - return conf -} - // Execute executes root CLI command. func Execute() { cc.Init(&cc.Config{ diff --git a/cmd/vpn-monitor/commands/root.go b/cmd/vpn-monitor/commands/root.go index 7427908a..8e269fb6 100644 --- a/cmd/vpn-monitor/commands/root.go +++ b/cmd/vpn-monitor/commands/root.go @@ -2,13 +2,10 @@ package commands import ( - "bytes" "context" "fmt" - "io" "log" "os" - "path/filepath" "time" cc "github.com/ivanpirog/coloredcobra" @@ -17,7 +14,6 @@ import ( "github.com/skycoin/skywire-utilities/pkg/cmdutil" "github.com/skycoin/skywire-utilities/pkg/logging" "github.com/skycoin/skywire-utilities/pkg/tcpproxy" - "github.com/skycoin/skywire/pkg/visor/visorconfig" "github.com/spf13/cobra" "github.com/skycoin/skywire-services/pkg/vpn-monitor/api" @@ -62,7 +58,7 @@ var RootCmd = &cobra.Command{ } mLogger := logging.NewMasterLogger() - conf := initConfig(confPath, visorBuildInfo, mLogger) + conf := api.InitConfig(confPath, mLogger) fmt.Println(conf.Version) @@ -104,30 +100,6 @@ var RootCmd = &cobra.Command{ }, } -func initConfig(confPath string, visorBuildInfo *buildinfo.Info, mLog *logging.MasterLogger) *visorconfig.V1 { - log := mLog.PackageLogger("vpn_monitor:config") - var r io.Reader - - if confPath != "" { - log.WithField("filepath", confPath).Info() - f, err := os.ReadFile(filepath.Clean(confPath)) - if err != nil { - log.WithError(err).Fatal("Failed to read config file.") - } - r = bytes.NewReader(f) - } - - conf, compat, err := visorconfig.Parse(log, r, confPath, visorBuildInfo) - if err != nil { - log.WithError(err).Fatal("Failed to read in config.") - } - if !compat { - log.Fatalf("failed to start skywire - config version is incompatible") - } - - return conf -} - // Execute executes root CLI command. func Execute() { cc.Init(&cc.Config{ diff --git a/pkg/public-visor-monitor/api/api.go b/pkg/public-visor-monitor/api/api.go index 6f9f363e..d13fc526 100644 --- a/pkg/public-visor-monitor/api/api.go +++ b/pkg/public-visor-monitor/api/api.go @@ -18,6 +18,8 @@ import ( "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/httputil" "github.com/skycoin/skywire-utilities/pkg/logging" + utilenv "github.com/skycoin/skywire-utilities/pkg/skyenv" + "github.com/skycoin/skywire/pkg/app/appserver" "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/transport/network" "github.com/skycoin/skywire/pkg/visor" @@ -279,3 +281,64 @@ func (api *API) startVisor(ctx context.Context, conf *visorconfig.V1) { } api.Visor = v } + +// InitConfig to initialize config +func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 { + log := mLog.PackageLogger("public_visor_monitor:config") + log.Info("Reading config from file.") + log.WithField("filepath", confPath).Info() + + oldConf, err := visorconfig.ReadFile(confPath) + if err != nil { + log.WithError(err).Fatal("Failed to read config file.") + } + var testEnv bool + if oldConf.Dmsg.Discovery == utilenv.TestDmsgDiscAddr { + testEnv = true + } + // have same services as old config + services := &visorconfig.Services{ + DmsgDiscovery: oldConf.Dmsg.Discovery, + TransportDiscovery: oldConf.Transport.Discovery, + AddressResolver: oldConf.Transport.AddressResolver, + RouteFinder: oldConf.Routing.RouteFinder, + RouteSetupNodes: oldConf.Routing.RouteSetupNodes, + UptimeTracker: oldConf.UptimeTracker.Addr, + ServiceDiscovery: oldConf.Launcher.ServiceDisc, + } + // update old config + conf, err := visorconfig.MakeDefaultConfig(mLog, &oldConf.SK, false, false, testEnv, false, false, confPath, "", services) + if err != nil { + log.WithError(err).Fatal("Failed to create config.") + } + + // have the same apps that the old config had + var newConfLauncherApps []appserver.AppConfig + for _, app := range conf.Launcher.Apps { + for _, oldApp := range oldConf.Launcher.Apps { + if app.Name == oldApp.Name { + newConfLauncherApps = append(newConfLauncherApps, app) + } + } + } + conf.Launcher.Apps = newConfLauncherApps + + conf.Version = oldConf.Version + conf.LocalPath = oldConf.LocalPath + conf.Launcher.BinPath = oldConf.Launcher.BinPath + conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr + conf.CLIAddr = oldConf.CLIAddr + conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs + + // following services are not needed + conf.STCP = nil + conf.Dmsgpty = nil + conf.Transport.PublicAutoconnect = false + + // save the config file + if err := conf.Flush(); err != nil { + log.WithError(err).Fatal("Failed to flush config to file.") + } + + return conf +} diff --git a/pkg/vpn-monitor/api/api.go b/pkg/vpn-monitor/api/api.go index 53dcab17..f2f8ed80 100644 --- a/pkg/vpn-monitor/api/api.go +++ b/pkg/vpn-monitor/api/api.go @@ -19,6 +19,7 @@ import ( "github.com/skycoin/skywire-utilities/pkg/cipher" "github.com/skycoin/skywire-utilities/pkg/httputil" "github.com/skycoin/skywire-utilities/pkg/logging" + utilenv "github.com/skycoin/skywire-utilities/pkg/skyenv" "github.com/skycoin/skywire/pkg/app/appserver" "github.com/skycoin/skywire/pkg/servicedisc" "github.com/skycoin/skywire/pkg/skyenv" @@ -353,3 +354,64 @@ func RunVpnClient(v *visor.Visor, serverPK cipher.PubKey, appName string) ([]app return sum, nil } + +// InitConfig to initialize config +func InitConfig(confPath string, mLog *logging.MasterLogger) *visorconfig.V1 { + log := mLog.PackageLogger("vpn_monitor:config") + log.Info("Reading config from file.") + log.WithField("filepath", confPath).Info() + + oldConf, err := visorconfig.ReadFile(confPath) + if err != nil { + log.WithError(err).Fatal("Failed to read config file.") + } + var testEnv bool + if oldConf.Dmsg.Discovery == utilenv.TestDmsgDiscAddr { + testEnv = true + } + // have same services as old config + services := &visorconfig.Services{ + DmsgDiscovery: oldConf.Dmsg.Discovery, + TransportDiscovery: oldConf.Transport.Discovery, + AddressResolver: oldConf.Transport.AddressResolver, + RouteFinder: oldConf.Routing.RouteFinder, + RouteSetupNodes: oldConf.Routing.RouteSetupNodes, + UptimeTracker: oldConf.UptimeTracker.Addr, + ServiceDiscovery: oldConf.Launcher.ServiceDisc, + } + // update old config + conf, err := visorconfig.MakeDefaultConfig(mLog, &oldConf.SK, false, false, testEnv, false, false, confPath, "", services) + if err != nil { + log.WithError(err).Fatal("Failed to create config.") + } + + // have the same apps that the old config had + var newConfLauncherApps []appserver.AppConfig + for _, app := range conf.Launcher.Apps { + for _, oldApp := range oldConf.Launcher.Apps { + if app.Name == oldApp.Name { + newConfLauncherApps = append(newConfLauncherApps, app) + } + } + } + conf.Launcher.Apps = newConfLauncherApps + + conf.Version = oldConf.Version + conf.LocalPath = oldConf.LocalPath + conf.Launcher.BinPath = oldConf.Launcher.BinPath + conf.Launcher.ServerAddr = oldConf.Launcher.ServerAddr + conf.CLIAddr = oldConf.CLIAddr + conf.Transport.TransportSetupPKs = oldConf.Transport.TransportSetupPKs + + // following services are not needed + conf.STCP = nil + conf.Dmsgpty = nil + conf.Transport.PublicAutoconnect = false + + // save the config file + if err := conf.Flush(); err != nil { + log.WithError(err).Fatal("Failed to flush config to file.") + } + + return conf +} From 84ce8cca689c83fd696855bc859c645811180eda Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 13 Oct 2023 05:30:35 +0000 Subject: [PATCH 3/5] upgrade golangci-lint to 1.52.1 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1773cb26..30b7ee51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: - name: Install Requirements run: | GO111MODULES=off; go mod vendor - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.50.1 + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.52.1 - name: Setup SSH Key Build and run e2e run : | make e2e-build From 11a37b5eff07a6b457bba3f39c522adea2385f58 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 13 Oct 2023 06:02:15 +0000 Subject: [PATCH 4/5] upgrade golang:alpine to 3.19 --- docker/images/skywire-visor/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/images/skywire-visor/Dockerfile b/docker/images/skywire-visor/Dockerfile index 1d58ab25..df279cc9 100755 --- a/docker/images/skywire-visor/Dockerfile +++ b/docker/images/skywire-visor/Dockerfile @@ -1,7 +1,7 @@ ARG image_tag=e2e ARG base=alpine -FROM golang:alpine3.13 as builder +FROM golang:alpine3.19 as builder ARG BUILDINFO_LDFLAGS ARG CGO_ENABLED=0 From 30d6c03cab631c923449098d7a3c0d37d141f8c4 Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Fri, 13 Oct 2023 06:19:28 +0000 Subject: [PATCH 5/5] upgrade golang:alpine to 3.17 --- docker/images/skywire-visor/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/images/skywire-visor/Dockerfile b/docker/images/skywire-visor/Dockerfile index df279cc9..a2f76cd2 100755 --- a/docker/images/skywire-visor/Dockerfile +++ b/docker/images/skywire-visor/Dockerfile @@ -1,7 +1,7 @@ ARG image_tag=e2e ARG base=alpine -FROM golang:alpine3.19 as builder +FROM golang:alpine3.17 as builder ARG BUILDINFO_LDFLAGS ARG CGO_ENABLED=0