Skip to content

Commit

Permalink
Add version stamp to binary and include in heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo committed Jan 28, 2021
1 parent 83de732 commit 6d55578
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/certusone/wormhole/bridge/pkg/version"
"os"

"github.com/spf13/cobra"
Expand All @@ -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() {
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions bridge/pkg/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package p2p
import (
"context"
"fmt"
"github.com/certusone/wormhole/bridge/pkg/version"
"github.com/prometheus/client_golang/prometheus"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions bridge/pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package version

// Wormhole release version injected by the compiler.
var version = "development"

func Version() string {
return version
}
4 changes: 3 additions & 1 deletion proto/gossip/v1/gossip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6d55578

Please sign in to comment.