Skip to content

Commit e731672

Browse files
authored
feat: version checking for core components (#1756)
Currently we often have a situation when our clients (both suppliers and customers) don't know whether a new version of the platform has been released. To avoid this we've done a simple console notification as a warning about whether it's time to update.
1 parent 90f597d commit e731672

File tree

10 files changed

+837
-6
lines changed

10 files changed

+837
-6
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ifeq ($(WITH_NL),true)
6868
NL_TAGS := nl
6969
endif
7070

71-
LDFLAGS = -X github.com/sonm-io/core/cmd.AppVersion=$(FULL_VERSION)
71+
LDFLAGS = -X github.com/sonm-io/core/insonmnia/version.Version=$(FULL_VERSION)
7272

7373
.PHONY: fmt vet test
7474

@@ -190,6 +190,7 @@ mock: build_mockgen
190190
mockgen -package sonm -destination proto/marketplace_mock.go -source proto/marketplace.pb.go
191191
mockgen -package sonm -destination proto/dwh_mock.go -source proto/dwh.pb.go
192192
mockgen -package node -destination insonmnia/node/server_mock.go -source insonmnia/node/server.go
193+
mockgen -package version -destination insonmnia/version/version_mock.go -source insonmnia/version/version.go
193194

194195
clean:
195196
rm -f ${WORKER} ${CLI} ${NODE} ${AUTOCLI} ${RENDEZVOUS}

cmd/cli/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package main
33
import (
44
"os"
55

6-
"github.com/sonm-io/core/cmd"
76
"github.com/sonm-io/core/cmd/cli/commands"
7+
"github.com/sonm-io/core/insonmnia/version"
88
)
99

1010
func main() {
11-
root := commands.Root(cmd.AppVersion)
11+
root := commands.Root(version.Version)
1212
if err := root.Execute(); err != nil {
1313
commands.ShowError(root, err.Error(), nil)
1414
os.Exit(1)

cmd/cobra.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import (
77
"strings"
88

99
"github.com/mitchellh/go-homedir"
10+
"github.com/sonm-io/core/insonmnia/version"
1011
"github.com/sonm-io/core/util"
1112
"github.com/spf13/cobra"
1213
"github.com/spf13/pflag"
1314
)
1415

1516
var (
16-
AppVersion string
17-
app = AppContext{
17+
app = AppContext{
1818
Name: path.Base(os.Args[0]),
19-
Version: AppVersion,
19+
Version: version.Version,
2020
}
2121
showVersion bool
2222
)

cmd/node/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/sonm-io/core/cmd"
99
"github.com/sonm-io/core/insonmnia/logging"
1010
"github.com/sonm-io/core/insonmnia/node"
11+
"github.com/sonm-io/core/insonmnia/version"
1112
"github.com/sonm-io/core/util/metrics"
1213
"golang.org/x/sync/errgroup"
1314
)
@@ -28,6 +29,7 @@ func run(app cmd.AppContext) error {
2829
}
2930

3031
ctx := ctxlog.WithLogger(context.Background(), log)
32+
version.ValidateVersion(ctx, version.NewLogObserver(log.Sugar()))
3133

3234
wg, ctx := errgroup.WithContext(ctx)
3335
wg.Go(func() error {

cmd/optimus/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/noxiouz/zapctx/ctxlog"
88
"github.com/sonm-io/core/cmd"
9+
"github.com/sonm-io/core/insonmnia/version"
910
"github.com/sonm-io/core/optimus"
1011
"go.uber.org/zap"
1112
"go.uber.org/zap/zapcore"
@@ -45,6 +46,7 @@ func run(app cmd.AppContext) error {
4546
}
4647

4748
ctx := ctxlog.WithLogger(context.Background(), log)
49+
version.ValidateVersion(ctx, version.NewLogObserver(log.Sugar()))
4850
bot, err := optimus.NewOptimus(cfg, optimus.WithVersion(app.Version), optimus.WithLog(log.Sugar()))
4951
if err != nil {
5052
return fmt.Errorf("failed to create Optimus: %v", err)

cmd/worker/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/sonm-io/core/cmd"
1212
"github.com/sonm-io/core/insonmnia/logging"
1313
"github.com/sonm-io/core/insonmnia/state"
14+
"github.com/sonm-io/core/insonmnia/version"
1415
"github.com/sonm-io/core/insonmnia/worker"
1516
"github.com/sonm-io/core/util/metrics"
1617
"go.uber.org/zap"
@@ -34,6 +35,7 @@ func run(app cmd.AppContext) error {
3435
return fmt.Errorf("failed to build logger instance: %s", err)
3536
}
3637
ctx = log.WithLogger(ctx, logger)
38+
version.ValidateVersion(ctx, version.NewLogObserver(logger.Sugar()))
3739

3840
storage, err := state.NewState(ctx, &cfg.Storage)
3941
if err != nil {

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/asaskevich/govalidator v0.0.0-20180319081651-7d2e70ef918f
1717
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a
1818
github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861 // indirect
19+
github.com/blang/semver v3.5.1+incompatible
1920
github.com/boltdb/bolt v1.3.1
2021
github.com/btcsuite/btcd v0.0.0-20171023093315-c7588cbf7690
2122
github.com/c2h5oh/datasize v0.0.0-20171227191756-4eba002a5eae

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a h1:BtpsbiV638WQZwhA98
2424
github.com/beorn7/perks v0.0.0-20160804104726-4c0e84591b9a/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
2525
github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861 h1:x17NvoJaphEzay72TFej4OSSsgu3xRYBLkbIwdofS/4=
2626
github.com/bifurcation/mint v0.0.0-20181105071958-a14404e9a861/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU=
27+
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
28+
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
2729
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
2830
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
2931
github.com/btcsuite/btcd v0.0.0-20171023093315-c7588cbf7690 h1:YSTjdPEsX8T2D31S9U7c4xxo0sQGa6TZ65cpCd7yVqU=

0 commit comments

Comments
 (0)