Ver código fonte

Add version stamp to binary and include in heartbeat

Leo 4 anos atrás
pai
commit
6d555789d6

+ 5 - 1
Makefile

@@ -9,6 +9,8 @@ PREFIX ?= /usr/local
 OUT = build
 BIN = $(OUT)/bin
 
+VERSION = $(shell git describe --tags --dirty)
+
 .PHONY: dirs
 dirs: Makefile
 	@mkdir -p $(BIN)
@@ -27,7 +29,9 @@ bridge: $(BIN)/guardiand
 
 .PHONY: $(BIN)/guardiand
 $(BIN)/guardiand: dirs generate
-	cd bridge && go build -mod=readonly -o ../$(BIN)/guardiand github.com/certusone/wormhole/bridge
+	cd bridge && go build -ldflags "-X github.com/certusone/wormhole/bridge/pkg/version.version=${VERSION}" \
+	  -mod=readonly -o ../$(BIN)/guardiand \
+	  github.com/certusone/wormhole/bridge
 
 .PHONY: agent
 agent: $(BIN)/guardiand-solana-agent

+ 11 - 0
bridge/cmd/root.go

@@ -2,6 +2,7 @@ package cmd
 
 import (
 	"fmt"
+	"github.com/certusone/wormhole/bridge/pkg/version"
 	"os"
 
 	"github.com/spf13/cobra"
@@ -20,6 +21,15 @@ var rootCmd = &cobra.Command{
 	Short: "Wormhole bridge server",
 }
 
+// Top-level version subcommand
+var versionCmd = &cobra.Command{
+	Use:   "version",
+	Short: "Display binary version information",
+	Run: func(cmd *cobra.Command, args []string) {
+		fmt.Println(version.Version())
+	},
+}
+
 // Execute adds all child commands to the root command and sets flags appropriately.
 // This is called by main.main(). It only needs to happen once to the rootCmd.
 func Execute() {
@@ -37,6 +47,7 @@ func init() {
 	rootCmd.AddCommand(guardiand.KeygenCmd)
 	rootCmd.AddCommand(guardiand.AdminCmd)
 	rootCmd.AddCommand(guardiand.TemplateCmd)
+	rootCmd.AddCommand(versionCmd)
 }
 
 // initConfig reads in config file and ENV variables if set.

+ 2 - 0
bridge/pkg/p2p/p2p.go

@@ -3,6 +3,7 @@ package p2p
 import (
 	"context"
 	"fmt"
+	"github.com/certusone/wormhole/bridge/pkg/version"
 	"github.com/prometheus/client_golang/prometheus"
 	"strings"
 	"time"
@@ -191,6 +192,7 @@ func Run(obsvC chan *gossipv1.SignedObservation,
 							NodeName:  nodeName,
 							Counter:   ctr,
 							Timestamp: time.Now().UnixNano(),
+							Version:   version.Version(),
 						}}}
 
 					b, err := proto.Marshal(&msg)

+ 8 - 0
bridge/pkg/version/version.go

@@ -0,0 +1,8 @@
+package version
+
+// Wormhole release version injected by the compiler.
+var version = "development"
+
+func Version() string {
+	return version
+}

+ 3 - 1
proto/gossip/v1/gossip.proto

@@ -27,8 +27,10 @@ message Heartbeat {
   }
   repeated Network networks = 4;
 
+  // Human-readable representation of the current bridge node release.
+  string version = 5;
+
   // TODO: include statement of gk public key?
-  // TODO: software version/release
 }
 
 // A SignedObservation is a signed statement by a given guardian node