Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding cosmovisor version command #10103

Merged
merged 35 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8688902
setting up cobra for `cosmovisor version` command
spoo-bar Sep 9, 2021
68ac1d3
adding Version variable to store during build time
spoo-bar Sep 13, 2021
2c43589
typo fix
spoo-bar Sep 13, 2021
2550790
regex check to get version in appropriate format
spoo-bar Sep 13, 2021
daf32fb
removing cobra and checking version arg
spoo-bar Sep 13, 2021
5139fde
adding tests related to version command
spoo-bar Sep 13, 2021
824220b
running comsovisor commands after the application
spoo-bar Sep 13, 2021
8164365
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 13, 2021
765b24e
added changelog and some doc
spoo-bar Sep 13, 2021
65baaca
updating makefile to get version from git tag
spoo-bar Sep 13, 2021
61ec885
updating readme docs for `version` cmd
spoo-bar Sep 13, 2021
186f76c
Update cosmovisor/CHANGELOG.md
spoo-bar Sep 13, 2021
2fb3122
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 13, 2021
535f943
Merge branch 'spoorthi/9999-cosmovisor-version-cmd' of https://github…
spoo-bar Sep 14, 2021
bd3c30a
removing version formatting
spoo-bar Sep 14, 2021
17949bb
updating readme
spoo-bar Sep 14, 2021
df73124
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 14, 2021
f541bec
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 14, 2021
9d158bd
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 14, 2021
312b7b0
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 16, 2021
b341057
updating on feedback
spoo-bar Sep 16, 2021
8d0388b
Merge branch 'spoorthi/9999-cosmovisor-version-cmd' of https://github…
spoo-bar Sep 16, 2021
b7f7eda
removing empty line
spoo-bar Sep 16, 2021
892ab21
print cosmovisor version befor application version
spoo-bar Sep 16, 2021
a7314c3
inlining printVersion
spoo-bar Sep 16, 2021
cdce913
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 16, 2021
84b9fd6
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 17, 2021
00103c0
Update cosmovisor/CHANGELOG.md
jgimeno Sep 17, 2021
fb9520f
Update cosmovisor/README.md
jgimeno Sep 17, 2021
816f480
Update cosmovisor/README.md
jgimeno Sep 17, 2021
8a24d16
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
jgimeno Sep 17, 2021
65b44ed
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 21, 2021
ad903e1
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 21, 2021
ccfeb8f
Merge branch 'master' into spoorthi/9999-cosmovisor-version-cmd
spoo-bar Sep 21, 2021
b1e876d
updating go.mod for go1.17
spoo-bar Sep 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 which returns the version of the cosmovisor along with the version of the application.
jgimeno marked this conversation as resolved.
Show resolved Hide resolved


### 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
14 changes: 14 additions & 0 deletions cosmovisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ 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

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

However, to determine the version of Cosmovisor being run, the following command can be run.
spoo-bar marked this conversation as resolved.
Show resolved Hide resolved
```
cosmovisor version
```
This returns the version of the `Cosmos SDK` application as well as the version of Cosmovisor as shown below
jgimeno marked this conversation as resolved.
Show resolved Hide resolved
```
0.43.0-beta1-319-ge3aec1840
Cosmovisor Version: v0.1.0-85-g65baacac0
spoo-bar marked this conversation as resolved.
Show resolved Hide resolved
```


### Detecting Upgrades

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

func RunCosmovisorCommands(args []string) {
spoo-bar marked this conversation as resolved.
Show resolved Hide resolved

if isVersionCommand(args) {
printVersion()
}

}
19 changes: 19 additions & 0 deletions cosmovisor/cmd/cosmovisor/cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"fmt"
"strings"
)

// Cosmovisor version value. Set during build
spoo-bar marked this conversation as resolved.
Show resolved Hide resolved
var Version string

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

func printVersion() {

spoo-bar marked this conversation as resolved.
Show resolved Hide resolved
fmt.Println("Cosmovisor Version: ", Version)

}
spoo-bar marked this conversation as resolved.
Show resolved Hide resolved
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)
})
}
}
5 changes: 5 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,7 @@ func main() {

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

cfg, err := cosmovisor.GetConfigFromEnv()
if err != nil {
return err
Expand All @@ -34,5 +36,8 @@ 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.")
}

// Run cosmosvisor commands e.g `cosmovisor version`
spoo-bar marked this conversation as resolved.
Show resolved Hide resolved
cmd.RunCosmovisorCommands(args)
return err
}
4 changes: 4 additions & 0 deletions cosmovisor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ module github.com/cosmos/cosmos-sdk/cosmovisor
go 1.15

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
)
394 changes: 377 additions & 17 deletions cosmovisor/go.sum

Large diffs are not rendered by default.