Add version stamp to binary and include in heartbeat

This commit is contained in:
Leo 2021-01-28 21:46:09 +01:00
parent 83de7325c4
commit 6d555789d6
5 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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.

View File

@ -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)

View File

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

View File

@ -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