Skip to content

Commit

Permalink
Merge branch 'master' into ty/fix-chain_id
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Sep 21, 2021
2 parents 72ad96b + 2dd4872 commit b784b28
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 32 deletions.
2 changes: 2 additions & 0 deletions cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

+ [\#8590](https://github.com/cosmos/cosmos-sdk/pull/8590) File watcher for cosmovisor. Instead of parsing logs from stdin and stderr, we watch the `<DAEMON_HOME>/data/upgrade-info.json` file updates using polling mechanism.
+ [\#10128](https://github.com/cosmos/cosmos-sdk/pull/10128) Change default value of `DAEMON_RESTART_AFTER_UPGRADE` to `true`.
+ [\#9999](https://github.com/cosmos/cosmos-sdk/issues/9999) Added `version` command that returns the cosmovisor version and the application version.


### Improvements

Expand Down
3 changes: 2 additions & 1 deletion cosmovisor/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/usr/bin/make -f

VERSION := $(shell echo $(shell git describe --always --match "cosmovisor/v*") | sed 's/^cosmovisor[/]//')

all: cosmovisor test

cosmovisor:
go build -mod=readonly ./cmd/cosmovisor
go build -ldflags="-X 'github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor/cmd.Version=$(VERSION)'" -mod=readonly ./cmd/cosmovisor

test:
go test -mod=readonly -race ./...
Expand Down
15 changes: 15 additions & 0 deletions cosmovisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ In order to support downloadable binaries, a tarball for each upgrade binary wil

The `DAEMON` specific code and operations (e.g. tendermint config, the application db, syncing blocks, etc.) all work as expected. The application binaries' directives such as command-line flags and environment variables also work as expected.

### Commands

Because Cosmovisor is meant to be used as a wrapper for a Cosmos SDK application, it does not require many commands.

To determine the version of Cosmovisor, run the following command:
```
cosmovisor version
```
The output of the `cosmovisor version` command shows the version of the Cosmos SDK application and the version of Cosmovisor:

```
Cosmovisor Version: v0.1.0-85-g65baacac0
0.43.0-beta1-319-ge3aec1840
```


### Detecting Upgrades

Expand Down
8 changes: 8 additions & 0 deletions cosmovisor/cmd/cosmovisor/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cmd

// RunCosmovisorCommands executes cosmosvisor commands e.g `cosmovisor version`
func RunCosmovisorCommands(args []string) {
if isVersionCommand(args) {
printVersion()
}
}
15 changes: 15 additions & 0 deletions cosmovisor/cmd/cosmovisor/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"fmt"
"strings"
)

// Version represents Cosmovisor version value. Set during build
var Version string

func isVersionCommand(args []string) bool {
return len(args) == 1 && strings.EqualFold(args[0], "version")
}

func printVersion() { fmt.Println("Cosmovisor Version: ", Version) }
40 changes: 40 additions & 0 deletions cosmovisor/cmd/cosmovisor/cmd/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestIsVersionCommand(t *testing.T) {
cases := []struct {
name string
args []string
expectRes bool
}{{
name: "valid args - lowercase",
args: []string{"version"},
expectRes: true,
}, {
name: "typo",
args: []string{"vrsion"},
expectRes: false,
}, {
name: "non version command",
args: []string{"start"},
expectRes: false,
}, {
name: "incorrect format",
args: []string{"start", "version"},
expectRes: false,
}}

for i := range cases {
tc := cases[i]
t.Run(tc.name, func(t *testing.T) {
require := require.New(t)
res := isVersionCommand(tc.args)
require.Equal(tc.expectRes, res)
})
}
}
4 changes: 4 additions & 0 deletions cosmovisor/cmd/cosmovisor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/cosmos/cosmos-sdk/cosmovisor"
"github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor/cmd"
)

func main() {
Expand All @@ -16,6 +17,8 @@ func main() {

// Run is the main loop, but returns an error
func Run(args []string) error {
cmd.RunCosmovisorCommands(args)

cfg, err := cosmovisor.GetConfigFromEnv()
if err != nil {
return err
Expand All @@ -34,5 +37,6 @@ func Run(args []string) error {
if doUpgrade && err == nil {
fmt.Println("[cosmovisor] upgrade detected, DAEMON_RESTART_AFTER_UPGRADE is off. Verify new upgrade and start cosmovisor again.")
}

return err
}
35 changes: 21 additions & 14 deletions cosmovisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,42 @@ module github.com/cosmos/cosmos-sdk/cosmovisor
go 1.17

require (
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-getter v1.4.1
github.com/otiai10/copy v1.4.2
github.com/stretchr/testify v1.7.0
google.golang.org/api v0.44.0 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

require (
cloud.google.com/go v0.45.1 // indirect
cloud.google.com/go v0.81.0 // indirect
cloud.google.com/go/storage v1.10.0 // indirect
github.com/aws/aws-sdk-go v1.15.78 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/go-cleanhttp v0.5.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/mitchellh/go-homedir v1.0.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/ulikunitz/xz v0.5.5 // indirect
go.opencensus.io v0.22.0 // indirect
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/api v0.9.0 // indirect
google.golang.org/appengine v1.6.1 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
google.golang.org/grpc v1.21.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 // indirect
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.1.2 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
)
Loading

0 comments on commit b784b28

Please sign in to comment.