From 8a46068224ece29d9e239e0782dcfbcef106db50 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 22:38:33 +0400 Subject: [PATCH 1/9] Add build information to binaries --- Makefile | 25 ++++++++++++++++++++----- cmd/hypervisor/commands/gen-config.go | 12 ++++++------ pkg/buildinfo/buildinfo.go | 9 +++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 pkg/buildinfo/buildinfo.go diff --git a/Makefile b/Makefile index 6dac85287a..9a1c1bb216 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,13 @@ .PHONY : docker-apps docker-bin docker-volume .PHONY : docker-run docker-stop +VERSION := 0.1.0 # 0.1.0 is the first possible version in semver + +RFC_3339 := "+%Y-%m-%dT%H:%M:%SZ" +DATE := $(shell date -u $(RFC_3339)) +COMMIT := $(shell git rev-list -1 HEAD) + +PROJECT_BASE := github.com/SkycoinProject/skywire-mainnet OPTS?=GO111MODULE=on DOCKER_IMAGE?=skywire-runner # docker image to use for running skywire-visor.`golang`, `buildpack-deps:stretch-scm` is OK too DOCKER_NETWORK?=SKYNET @@ -14,7 +21,16 @@ DOCKER_NODE?=SKY01 DOCKER_OPTS?=GO111MODULE=on GOOS=linux # go options for compiling for docker container TEST_OPTS?=-race -tags no_ci -cover -timeout=5m TEST_OPTS_NOCI?=-race -cover -timeout=5m -v -BUILD_OPTS?= + +BUILDINFO_PATH := $(PROJECT_BASE)/pkg/buildinfo + +BUILDINFO_VERSION := -X $(BUILDINFO_PATH).Version=$(VERSION) +BUILDINFO_DATE := -X $(BUILDINFO_PATH).Date=$(DATE) +BUILDINFO_COMMIT := -X $(BUILDINFO_PATH).Commit=$(COMMIT) + +BUILDINFO?=-ldflags="$(BUILDINFO_VERSION) $(BUILDINFO_DATE) $(BUILDINFO_COMMIT)" + +BUILD_OPTS?=$(BUILDINFO) check: lint test ## Run linters and tests @@ -75,9 +91,9 @@ install-linters: ## Install linters ${OPTS} go get -u golang.org/x/tools/cmd/goimports format: ## Formats the code. Must have goimports installed (use make install-linters). - ${OPTS} goimports -w -local github.com/SkycoinProject/skywire ./pkg - ${OPTS} goimports -w -local github.com/SkycoinProject/skywire ./cmd - ${OPTS} goimports -w -local github.com/SkycoinProject/skywire ./internal + ${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg + ${OPTS} goimports -w -local ${PROJECT_BASE} ./cmd + ${OPTS} goimports -w -local ${PROJECT_BASE} ./internal dep: ## Sorts dependencies ${OPTS} go mod vendor -v @@ -158,7 +174,6 @@ run-syslog: ## Run syslog-ng in docker. Logs are mounted under /tmp/syslog -docker container rm syslog-ng -f docker run -d -p 514:514/udp -v /tmp/syslog:/var/log --name syslog-ng balabit/syslog-ng:latest - integration-startup: ## Starts up the required transports between `skywire-visor`s of interactive testing environment ./integration/startup.sh diff --git a/cmd/hypervisor/commands/gen-config.go b/cmd/hypervisor/commands/gen-config.go index e6e223ca29..0461a6e0fb 100644 --- a/cmd/hypervisor/commands/gen-config.go +++ b/cmd/hypervisor/commands/gen-config.go @@ -15,7 +15,7 @@ var ( output string replace bool configLocType = pathutil.WorkingDirLoc - testenv bool + testEnv bool ) // nolint:gochecknoinits @@ -23,13 +23,13 @@ func init() { outputUsage := "path of output config file. Uses default of 'type' flag if unspecified." replaceUsage := "whether to allow rewrite of a file that already exists." configLocTypeUsage := fmt.Sprintf("config generation mode. Valid values: %v", pathutil.AllConfigLocationTypes()) - testEnv := "whether to use production or test deployment service." + testEnvUsage := "whether to use production or test deployment service." rootCmd.AddCommand(genConfigCmd) genConfigCmd.Flags().StringVarP(&output, "output", "o", "", outputUsage) genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, replaceUsage) genConfigCmd.Flags().VarP(&configLocType, "type", "m", configLocTypeUsage) - genConfigCmd.Flags().BoolVarP(&testenv, "testing-environment", "t", false, testEnv) + genConfigCmd.Flags().BoolVarP(&testEnv, "testing-environment", "t", false, testEnvUsage) } // nolint:gochecknoglobals @@ -50,11 +50,11 @@ var genConfigCmd = &cobra.Command{ var conf hypervisor.Config switch configLocType { case pathutil.WorkingDirLoc: - conf = hypervisor.GenerateWorkDirConfig(testenv) + conf = hypervisor.GenerateWorkDirConfig(testEnv) case pathutil.HomeLoc: - conf = hypervisor.GenerateHomeConfig(testenv) + conf = hypervisor.GenerateHomeConfig(testEnv) case pathutil.LocalLoc: - conf = hypervisor.GenerateLocalConfig(testenv) + conf = hypervisor.GenerateLocalConfig(testEnv) default: log.Fatalln("invalid config type:", configLocType) } diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go new file mode 100644 index 0000000000..07e0bc2ee0 --- /dev/null +++ b/pkg/buildinfo/buildinfo.go @@ -0,0 +1,9 @@ +package buildinfo + +const unknown = "unknown" + +var ( + Version = unknown + Commit = unknown + Date = unknown +) From 1b35030989af7fd8a901bbf9925c9f1da8bc07ca Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:14:23 +0400 Subject: [PATCH 2/9] Get build version from git describe --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9a1c1bb216..e1491e0e06 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ .PHONY : docker-apps docker-bin docker-volume .PHONY : docker-run docker-stop -VERSION := 0.1.0 # 0.1.0 is the first possible version in semver +VERSION := $(shell git describe) RFC_3339 := "+%Y-%m-%dT%H:%M:%SZ" DATE := $(shell date -u $(RFC_3339)) From d8db2d717d30e78db8c674f996f0ad542a5219cd Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:14:52 +0400 Subject: [PATCH 3/9] Print build information on start of all cmd's --- cmd/dmsgpty/dmsgpty.go | 11 ++++++++++- cmd/hypervisor/hypervisor.go | 11 ++++++++++- cmd/setup-node/setup-node.go | 11 ++++++++++- cmd/skywire-cli/skywire-cli.go | 7 +++++++ cmd/skywire-visor/skywire-visor.go | 7 +++++++ pkg/buildinfo/buildinfo.go | 10 ++++++++++ 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/cmd/dmsgpty/dmsgpty.go b/cmd/dmsgpty/dmsgpty.go index 92ce4bb87e..4794bea214 100644 --- a/cmd/dmsgpty/dmsgpty.go +++ b/cmd/dmsgpty/dmsgpty.go @@ -1,7 +1,16 @@ package main -import "github.com/SkycoinProject/skywire-mainnet/cmd/dmsgpty/commands" +import ( + "log" + + "github.com/SkycoinProject/skywire-mainnet/cmd/dmsgpty/commands" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" +) func main() { + if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + commands.Execute() } diff --git a/cmd/hypervisor/hypervisor.go b/cmd/hypervisor/hypervisor.go index cde4e7977a..295f1475b4 100644 --- a/cmd/hypervisor/hypervisor.go +++ b/cmd/hypervisor/hypervisor.go @@ -3,8 +3,17 @@ skywire hypervisor */ package main -import "github.com/SkycoinProject/skywire-mainnet/cmd/hypervisor/commands" +import ( + "log" + + "github.com/SkycoinProject/skywire-mainnet/cmd/hypervisor/commands" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" +) func main() { + if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + commands.Execute() } diff --git a/cmd/setup-node/setup-node.go b/cmd/setup-node/setup-node.go index e882d663e2..b6dbd77de4 100644 --- a/cmd/setup-node/setup-node.go +++ b/cmd/setup-node/setup-node.go @@ -1,7 +1,16 @@ package main -import "github.com/SkycoinProject/skywire-mainnet/cmd/setup-node/commands" +import ( + "log" + + "github.com/SkycoinProject/skywire-mainnet/cmd/setup-node/commands" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" +) func main() { + if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + commands.Execute() } diff --git a/cmd/skywire-cli/skywire-cli.go b/cmd/skywire-cli/skywire-cli.go index 66d50e0a3d..564903d6f8 100644 --- a/cmd/skywire-cli/skywire-cli.go +++ b/cmd/skywire-cli/skywire-cli.go @@ -4,9 +4,16 @@ CLI for skywire visor package main import ( + "log" + "github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/commands" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { + if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + commands.Execute() } diff --git a/cmd/skywire-visor/skywire-visor.go b/cmd/skywire-visor/skywire-visor.go index 282da4c41f..089aa5034d 100644 --- a/cmd/skywire-visor/skywire-visor.go +++ b/cmd/skywire-visor/skywire-visor.go @@ -4,9 +4,16 @@ skywire visor package main import ( + "log" + "github.com/SkycoinProject/skywire-mainnet/cmd/skywire-visor/commands" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { + if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + commands.Execute() } diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go index 07e0bc2ee0..0d095435f3 100644 --- a/pkg/buildinfo/buildinfo.go +++ b/pkg/buildinfo/buildinfo.go @@ -1,5 +1,10 @@ package buildinfo +import ( + "fmt" + "io" +) + const unknown = "unknown" var ( @@ -7,3 +12,8 @@ var ( Commit = unknown Date = unknown ) + +func WriteTo(w io.Writer) (n int, err error) { + msg := fmt.Sprintf("Version %q built on %q agaist commit %q\n", Version, Date, Commit) + return w.Write([]byte(msg)) +} From 0b17b150581a8f996593786111647004d5963fe8 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:32:57 +0400 Subject: [PATCH 4/9] Show node build info in HTTP endpoint --- Makefile | 6 ++--- cmd/dmsgpty/dmsgpty.go | 2 +- cmd/hypervisor/hypervisor.go | 2 +- cmd/setup-node/setup-node.go | 2 +- cmd/skywire-cli/skywire-cli.go | 2 +- cmd/skywire-visor/commands/root.go | 3 ++- cmd/skywire-visor/skywire-visor.go | 2 +- pkg/buildinfo/buildinfo.go | 36 +++++++++++++++++++++++++----- pkg/hypervisor/hypervisor.go | 2 +- pkg/visor/rpc.go | 5 +++-- pkg/visor/rpc_client.go | 3 ++- pkg/visor/visor.go | 3 --- 12 files changed, 47 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index e1491e0e06..a3700d8929 100644 --- a/Makefile +++ b/Makefile @@ -24,9 +24,9 @@ TEST_OPTS_NOCI?=-race -cover -timeout=5m -v BUILDINFO_PATH := $(PROJECT_BASE)/pkg/buildinfo -BUILDINFO_VERSION := -X $(BUILDINFO_PATH).Version=$(VERSION) -BUILDINFO_DATE := -X $(BUILDINFO_PATH).Date=$(DATE) -BUILDINFO_COMMIT := -X $(BUILDINFO_PATH).Commit=$(COMMIT) +BUILDINFO_VERSION := -X $(BUILDINFO_PATH).version=$(VERSION) +BUILDINFO_DATE := -X $(BUILDINFO_PATH).date=$(DATE) +BUILDINFO_COMMIT := -X $(BUILDINFO_PATH).commit=$(COMMIT) BUILDINFO?=-ldflags="$(BUILDINFO_VERSION) $(BUILDINFO_DATE) $(BUILDINFO_COMMIT)" diff --git a/cmd/dmsgpty/dmsgpty.go b/cmd/dmsgpty/dmsgpty.go index 4794bea214..8dc86470ae 100644 --- a/cmd/dmsgpty/dmsgpty.go +++ b/cmd/dmsgpty/dmsgpty.go @@ -8,7 +8,7 @@ import ( ) func main() { - if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { log.Printf("Failed to output build info: %v", err) } diff --git a/cmd/hypervisor/hypervisor.go b/cmd/hypervisor/hypervisor.go index 295f1475b4..bde7de2f64 100644 --- a/cmd/hypervisor/hypervisor.go +++ b/cmd/hypervisor/hypervisor.go @@ -11,7 +11,7 @@ import ( ) func main() { - if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { log.Printf("Failed to output build info: %v", err) } diff --git a/cmd/setup-node/setup-node.go b/cmd/setup-node/setup-node.go index b6dbd77de4..0409703ffb 100644 --- a/cmd/setup-node/setup-node.go +++ b/cmd/setup-node/setup-node.go @@ -8,7 +8,7 @@ import ( ) func main() { - if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { log.Printf("Failed to output build info: %v", err) } diff --git a/cmd/skywire-cli/skywire-cli.go b/cmd/skywire-cli/skywire-cli.go index 564903d6f8..bbe8f0f6fc 100644 --- a/cmd/skywire-cli/skywire-cli.go +++ b/cmd/skywire-cli/skywire-cli.go @@ -11,7 +11,7 @@ import ( ) func main() { - if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { log.Printf("Failed to output build info: %v", err) } diff --git a/cmd/skywire-visor/commands/root.go b/cmd/skywire-visor/commands/root.go index 7c916a93d9..56a4ada41f 100644 --- a/cmd/skywire-visor/commands/root.go +++ b/cmd/skywire-visor/commands/root.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/cobra" "github.com/SkycoinProject/skywire-mainnet/internal/utclient" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/restart" "github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil" "github.com/SkycoinProject/skywire-mainnet/pkg/visor" @@ -67,7 +68,7 @@ var rootCmd = &cobra.Command{ waitOsSignals(). stopNode() }, - Version: visor.Version, + Version: buildinfo.Get().Version, } func init() { diff --git a/cmd/skywire-visor/skywire-visor.go b/cmd/skywire-visor/skywire-visor.go index 089aa5034d..ec71526239 100644 --- a/cmd/skywire-visor/skywire-visor.go +++ b/cmd/skywire-visor/skywire-visor.go @@ -11,7 +11,7 @@ import ( ) func main() { - if _, err := buildinfo.WriteTo(log.Writer()); err != nil { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { log.Printf("Failed to output build info: %v", err) } diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go index 0d095435f3..bd114cb5d5 100644 --- a/pkg/buildinfo/buildinfo.go +++ b/pkg/buildinfo/buildinfo.go @@ -8,12 +8,38 @@ import ( const unknown = "unknown" var ( - Version = unknown - Commit = unknown - Date = unknown + version = unknown + commit = unknown + date = unknown ) -func WriteTo(w io.Writer) (n int, err error) { - msg := fmt.Sprintf("Version %q built on %q agaist commit %q\n", Version, Date, Commit) +func Version() string { + return version +} + +func Commit() string { + return commit +} + +func Date() string { + return date +} + +func Get() *Info { + return &Info{ + Version: Version(), + Commit: Commit(), + Date: Date(), + } +} + +type Info struct { + Version string `json:"version"` + Commit string `json:"commit"` + Date string `json:"date"` +} + +func (info *Info) WriteTo(w io.Writer) (n int, err error) { + msg := fmt.Sprintf("Version %q built on %q agaist commit %q\n", info.Version, info.Date, info.Commit) return w.Write([]byte(msg)) } diff --git a/pkg/hypervisor/hypervisor.go b/pkg/hypervisor/hypervisor.go index a5b05afce0..71901f80e3 100644 --- a/pkg/hypervisor/hypervisor.go +++ b/pkg/hypervisor/hypervisor.go @@ -148,9 +148,9 @@ func (m *Node) ServeHTTP(w http.ResponseWriter, req *http.Request) { r.Get("/user", m.users.UserInfo()) r.Post("/change-password", m.users.ChangePassword()) r.Get("/nodes", m.getNodes()) + r.Get("/nodes/{pk}", m.getNode()) r.Get("/nodes/{pk}/health", m.getHealth()) r.Get("/nodes/{pk}/uptime", m.getUptime()) - r.Get("/nodes/{pk}", m.getNode()) r.Get("/nodes/{pk}/apps", m.getApps()) r.Get("/nodes/{pk}/apps/{app}", m.getApp()) r.Put("/nodes/{pk}/apps/{app}", m.putApp()) diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index 0f36478829..64dbcd6606 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -12,6 +12,7 @@ import ( "github.com/google/uuid" "github.com/SkycoinProject/skywire-mainnet/pkg/app" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" ) @@ -144,7 +145,7 @@ func newTransportSummary(tm *transport.Manager, tp *transport.ManagedTransport, // Summary provides a summary of a Skywire Visor. type Summary struct { PubKey cipher.PubKey `json:"local_pk"` - NodeVersion string `json:"node_version"` + BuildInfo *buildinfo.Info `json:"build_info"` AppProtoVersion string `json:"app_protocol_version"` Apps []*AppState `json:"apps"` Transports []*TransportSummary `json:"transports"` @@ -161,7 +162,7 @@ func (r *RPC) Summary(_ *struct{}, out *Summary) error { }) *out = Summary{ PubKey: r.node.conf.Node.StaticPubKey, - NodeVersion: Version, + BuildInfo: buildinfo.Get(), AppProtoVersion: supportedProtocolVersion, Apps: r.node.Apps(), Transports: summaries, diff --git a/pkg/visor/rpc_client.go b/pkg/visor/rpc_client.go index 58bdf73e4c..89837f4b81 100644 --- a/pkg/visor/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -17,6 +17,7 @@ import ( "github.com/google/uuid" "github.com/SkycoinProject/skywire-mainnet/pkg/app" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/router" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/snet" @@ -424,7 +425,7 @@ func NewMockRPCClient(r *rand.Rand, maxTps int, maxRules int) (cipher.PubKey, RP client := &mockRPCClient{ s: &Summary{ PubKey: localPK, - NodeVersion: Version, + BuildInfo: buildinfo.Get(), AppProtoVersion: supportedProtocolVersion, Apps: []*AppState{ {Name: "foo.v1.0", AutoStart: false, Port: 10}, diff --git a/pkg/visor/visor.go b/pkg/visor/visor.go index fb1051e2f1..6385e82df6 100644 --- a/pkg/visor/visor.go +++ b/pkg/visor/visor.go @@ -56,9 +56,6 @@ var ( ErrNoConfigPath = errors.New("no config path") ) -// Version is the node version. -const Version = "0.0.1" - const supportedProtocolVersion = "0.0.1" var reservedPorts = map[routing.Port]string{0: "router", 1: "skychat", 3: "skysocks"} From d03071663f06934968d3c3d6bf96173567b33722 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:41:24 +0400 Subject: [PATCH 5/9] Fix output of build info on start --- cmd/dmsgpty/commands/root.go | 5 +++++ cmd/dmsgpty/dmsgpty.go | 7 ------- cmd/hypervisor/commands/root.go | 6 ++++++ cmd/hypervisor/hypervisor.go | 7 ------- cmd/setup-node/commands/root.go | 4 ++++ cmd/setup-node/setup-node.go | 7 ------- cmd/skywire-visor/commands/root.go | 4 ++++ cmd/skywire-visor/skywire-visor.go | 7 ------- 8 files changed, 19 insertions(+), 28 deletions(-) diff --git a/cmd/dmsgpty/commands/root.go b/cmd/dmsgpty/commands/root.go index 6f13031c3d..bdeafc9ad9 100644 --- a/cmd/dmsgpty/commands/root.go +++ b/cmd/dmsgpty/commands/root.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" "github.com/SkycoinProject/skywire-mainnet/internal/skyenv" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/dmsgpty" ) @@ -32,6 +33,10 @@ var rootCmd = &cobra.Command{ Use: "dmsgpty", Short: "Run commands over dmsg", PreRunE: func(*cobra.Command, []string) error { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + return readDstAddr() }, RunE: func(*cobra.Command, []string) error { diff --git a/cmd/dmsgpty/dmsgpty.go b/cmd/dmsgpty/dmsgpty.go index 8dc86470ae..83233da6c0 100644 --- a/cmd/dmsgpty/dmsgpty.go +++ b/cmd/dmsgpty/dmsgpty.go @@ -1,16 +1,9 @@ package main import ( - "log" - "github.com/SkycoinProject/skywire-mainnet/cmd/dmsgpty/commands" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { - if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { - log.Printf("Failed to output build info: %v", err) - } - commands.Execute() } diff --git a/cmd/hypervisor/commands/root.go b/cmd/hypervisor/commands/root.go index b80ebae8ce..804518da0f 100644 --- a/cmd/hypervisor/commands/root.go +++ b/cmd/hypervisor/commands/root.go @@ -3,6 +3,7 @@ package commands import ( "fmt" "net/http" + "os" "github.com/SkycoinProject/dmsg" "github.com/SkycoinProject/dmsg/disc" @@ -10,6 +11,7 @@ import ( "github.com/SkycoinProject/skycoin/src/util/logging" "github.com/spf13/cobra" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/hypervisor" "github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil" ) @@ -43,6 +45,10 @@ var rootCmd = &cobra.Command{ Use: "hypervisor", Short: "Manages Skywire App Nodes", Run: func(_ *cobra.Command, args []string) { + if _, err := buildinfo.Get().WriteTo(os.Stdout); err != nil { + log.Printf("Failed to output build info: %v", err) + } + if configPath == "" { configPath = pathutil.FindConfigPath(args, -1, configEnv, pathutil.HypervisorDefaults()) } diff --git a/cmd/hypervisor/hypervisor.go b/cmd/hypervisor/hypervisor.go index bde7de2f64..d049201954 100644 --- a/cmd/hypervisor/hypervisor.go +++ b/cmd/hypervisor/hypervisor.go @@ -4,16 +4,9 @@ skywire hypervisor package main import ( - "log" - "github.com/SkycoinProject/skywire-mainnet/cmd/hypervisor/commands" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { - if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { - log.Printf("Failed to output build info: %v", err) - } - commands.Execute() } diff --git a/cmd/setup-node/commands/root.go b/cmd/setup-node/commands/root.go index e9e32cba23..e415346caa 100644 --- a/cmd/setup-node/commands/root.go +++ b/cmd/setup-node/commands/root.go @@ -14,6 +14,7 @@ import ( logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/spf13/cobra" + "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/metrics" "github.com/SkycoinProject/skywire-mainnet/pkg/setup" ) @@ -29,6 +30,9 @@ var rootCmd = &cobra.Command{ Use: "setup-node [config.json]", Short: "Route Setup Node for skywire", Run: func(_ *cobra.Command, args []string) { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } logger := logging.MustGetLogger(tag) if syslogAddr != "" { diff --git a/cmd/setup-node/setup-node.go b/cmd/setup-node/setup-node.go index 0409703ffb..fbf1c7e2d7 100644 --- a/cmd/setup-node/setup-node.go +++ b/cmd/setup-node/setup-node.go @@ -1,16 +1,9 @@ package main import ( - "log" - "github.com/SkycoinProject/skywire-mainnet/cmd/setup-node/commands" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { - if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { - log.Printf("Failed to output build info: %v", err) - } - commands.Execute() } diff --git a/cmd/skywire-visor/commands/root.go b/cmd/skywire-visor/commands/root.go index 56a4ada41f..f8ef684bf9 100644 --- a/cmd/skywire-visor/commands/root.go +++ b/cmd/skywire-visor/commands/root.go @@ -59,6 +59,10 @@ var rootCmd = &cobra.Command{ Use: "skywire-visor [config-path]", Short: "Visor for skywire", Run: func(_ *cobra.Command, args []string) { + if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { + log.Printf("Failed to output build info: %v", err) + } + cfg.args = args cfg.startProfiler(). diff --git a/cmd/skywire-visor/skywire-visor.go b/cmd/skywire-visor/skywire-visor.go index ec71526239..282da4c41f 100644 --- a/cmd/skywire-visor/skywire-visor.go +++ b/cmd/skywire-visor/skywire-visor.go @@ -4,16 +4,9 @@ skywire visor package main import ( - "log" - "github.com/SkycoinProject/skywire-mainnet/cmd/skywire-visor/commands" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { - if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { - log.Printf("Failed to output build info: %v", err) - } - commands.Execute() } From 9014c82d5a2bce3fafa83d2fa2bbb1442c442bd1 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:53:36 +0400 Subject: [PATCH 6/9] Remove unnecessary version output in skywire-cli --- cmd/skywire-cli/skywire-cli.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/cmd/skywire-cli/skywire-cli.go b/cmd/skywire-cli/skywire-cli.go index bbe8f0f6fc..66d50e0a3d 100644 --- a/cmd/skywire-cli/skywire-cli.go +++ b/cmd/skywire-cli/skywire-cli.go @@ -4,16 +4,9 @@ CLI for skywire visor package main import ( - "log" - "github.com/SkycoinProject/skywire-mainnet/cmd/skywire-cli/commands" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" ) func main() { - if _, err := buildinfo.Get().WriteTo(log.Writer()); err != nil { - log.Printf("Failed to output build info: %v", err) - } - commands.Execute() } From f49ec5bd980fa67f61d990ba67b6da3a45b33db7 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:53:52 +0400 Subject: [PATCH 7/9] Add CLI command for visor version output --- cmd/skywire-cli/commands/node/version.go | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 cmd/skywire-cli/commands/node/version.go diff --git a/cmd/skywire-cli/commands/node/version.go b/cmd/skywire-cli/commands/node/version.go new file mode 100644 index 0000000000..859eff2dd6 --- /dev/null +++ b/cmd/skywire-cli/commands/node/version.go @@ -0,0 +1,27 @@ +package node + +import ( + "os" + + "github.com/spf13/cobra" +) + +func init() { + RootCmd.AddCommand(buildInfoCmd) +} + +var buildInfoCmd = &cobra.Command{ + Use: "version", + Short: "Obtains version and build info of the node", + Run: func(_ *cobra.Command, _ []string) { + client := rpcClient() + summary, err := client.Summary() + if err != nil { + log.Fatal("Failed to connect:", err) + } + + if _, err := summary.BuildInfo.WriteTo(os.Stdout); err != nil { + log.Fatal("Failed to output build info:", err) + } + }, +} From 6d8a860ee28c758f0c4ad3799688252da1ccae36 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 23:58:28 +0400 Subject: [PATCH 8/9] Fix linter errors --- pkg/buildinfo/buildinfo.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go index bd114cb5d5..f460f64aca 100644 --- a/pkg/buildinfo/buildinfo.go +++ b/pkg/buildinfo/buildinfo.go @@ -13,18 +13,22 @@ var ( date = unknown ) +// Version returns version from git describe. func Version() string { return version } +// Commit returns commit hash. func Commit() string { return commit } +// Date returns date of build in RFC3339 format. func Date() string { return date } +// Get returns build info summary. func Get() *Info { return &Info{ Version: Version(), @@ -33,13 +37,16 @@ func Get() *Info { } } +// Info is build info summary. type Info struct { Version string `json:"version"` Commit string `json:"commit"` Date string `json:"date"` } -func (info *Info) WriteTo(w io.Writer) (n int, err error) { +// WriteTo writes build info summary to io.Writer. +func (info *Info) WriteTo(w io.Writer) (int64, error) { msg := fmt.Sprintf("Version %q built on %q agaist commit %q\n", info.Version, info.Date, info.Commit) - return w.Write([]byte(msg)) + n, err := w.Write([]byte(msg)) + return int64(n), err } From 130dca7cd5780d48f637e7dc0a4ccbef2c08baa9 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Thu, 30 Jan 2020 01:00:16 +0400 Subject: [PATCH 9/9] Move buildinfo to util --- Makefile | 2 +- cmd/dmsgpty/commands/root.go | 2 +- cmd/hypervisor/commands/root.go | 2 +- cmd/setup-node/commands/root.go | 2 +- cmd/skywire-visor/commands/root.go | 2 +- pkg/{ => util}/buildinfo/buildinfo.go | 0 pkg/visor/rpc.go | 2 +- pkg/visor/rpc_client.go | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename pkg/{ => util}/buildinfo/buildinfo.go (100%) diff --git a/Makefile b/Makefile index a3700d8929..753675ec33 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ DOCKER_OPTS?=GO111MODULE=on GOOS=linux # go options for compiling for docker con TEST_OPTS?=-race -tags no_ci -cover -timeout=5m TEST_OPTS_NOCI?=-race -cover -timeout=5m -v -BUILDINFO_PATH := $(PROJECT_BASE)/pkg/buildinfo +BUILDINFO_PATH := $(PROJECT_BASE)/pkg/util/buildinfo BUILDINFO_VERSION := -X $(BUILDINFO_PATH).version=$(VERSION) BUILDINFO_DATE := -X $(BUILDINFO_PATH).date=$(DATE) diff --git a/cmd/dmsgpty/commands/root.go b/cmd/dmsgpty/commands/root.go index bdeafc9ad9..91039ebde1 100644 --- a/cmd/dmsgpty/commands/root.go +++ b/cmd/dmsgpty/commands/root.go @@ -10,8 +10,8 @@ import ( "github.com/spf13/cobra" "github.com/SkycoinProject/skywire-mainnet/internal/skyenv" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/dmsgpty" + "github.com/SkycoinProject/skywire-mainnet/pkg/util/buildinfo" ) var ptyCLI dmsgpty.CLI diff --git a/cmd/hypervisor/commands/root.go b/cmd/hypervisor/commands/root.go index 804518da0f..295eb4f4b1 100644 --- a/cmd/hypervisor/commands/root.go +++ b/cmd/hypervisor/commands/root.go @@ -11,8 +11,8 @@ import ( "github.com/SkycoinProject/skycoin/src/util/logging" "github.com/spf13/cobra" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/hypervisor" + "github.com/SkycoinProject/skywire-mainnet/pkg/util/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil" ) diff --git a/cmd/setup-node/commands/root.go b/cmd/setup-node/commands/root.go index e415346caa..5466d441b5 100644 --- a/cmd/setup-node/commands/root.go +++ b/cmd/setup-node/commands/root.go @@ -14,9 +14,9 @@ import ( logrussyslog "github.com/sirupsen/logrus/hooks/syslog" "github.com/spf13/cobra" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/metrics" "github.com/SkycoinProject/skywire-mainnet/pkg/setup" + "github.com/SkycoinProject/skywire-mainnet/pkg/util/buildinfo" ) var ( diff --git a/cmd/skywire-visor/commands/root.go b/cmd/skywire-visor/commands/root.go index f8ef684bf9..41f1faf9c0 100644 --- a/cmd/skywire-visor/commands/root.go +++ b/cmd/skywire-visor/commands/root.go @@ -23,8 +23,8 @@ import ( "github.com/spf13/cobra" "github.com/SkycoinProject/skywire-mainnet/internal/utclient" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/restart" + "github.com/SkycoinProject/skywire-mainnet/pkg/util/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/util/pathutil" "github.com/SkycoinProject/skywire-mainnet/pkg/visor" ) diff --git a/pkg/buildinfo/buildinfo.go b/pkg/util/buildinfo/buildinfo.go similarity index 100% rename from pkg/buildinfo/buildinfo.go rename to pkg/util/buildinfo/buildinfo.go diff --git a/pkg/visor/rpc.go b/pkg/visor/rpc.go index 64dbcd6606..58154f647c 100644 --- a/pkg/visor/rpc.go +++ b/pkg/visor/rpc.go @@ -12,9 +12,9 @@ import ( "github.com/google/uuid" "github.com/SkycoinProject/skywire-mainnet/pkg/app" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" + "github.com/SkycoinProject/skywire-mainnet/pkg/util/buildinfo" ) const ( diff --git a/pkg/visor/rpc_client.go b/pkg/visor/rpc_client.go index 89837f4b81..f5c17d4fba 100644 --- a/pkg/visor/rpc_client.go +++ b/pkg/visor/rpc_client.go @@ -17,12 +17,12 @@ import ( "github.com/google/uuid" "github.com/SkycoinProject/skywire-mainnet/pkg/app" - "github.com/SkycoinProject/skywire-mainnet/pkg/buildinfo" "github.com/SkycoinProject/skywire-mainnet/pkg/router" "github.com/SkycoinProject/skywire-mainnet/pkg/routing" "github.com/SkycoinProject/skywire-mainnet/pkg/snet" "github.com/SkycoinProject/skywire-mainnet/pkg/snet/snettest" "github.com/SkycoinProject/skywire-mainnet/pkg/transport" + "github.com/SkycoinProject/skywire-mainnet/pkg/util/buildinfo" ) var (