feat(cosmovisor): add install disclaimer and config command (#15361)

This commit is contained in:
Julien Robert 2023-03-12 21:57:13 +01:00 committed by GitHub
parent 8f8afd1704
commit 4c1e6a576e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 80 additions and 63 deletions

View File

@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
## [Unreleased]
## Features
* [#15361](https://github.com/cosmos/cosmos-sdk/pull/15361) Add `cosmovisor config` command to display the configuration used by cosmovisor.
## Client Breaking Changes
* [#14881](https://github.com/cosmos/cosmos-sdk/pull/14881) Cosmovisor supports only upgrade plan with a checksum. This is enforced by the `x/upgrade` module for better security.
@ -46,7 +50,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#14881](https://github.com/cosmos/cosmos-sdk/pull/14881) Refactor Cosmovisor to depend only on the `x/upgrade` module.
* [#15362](https://github.com/cosmos/cosmos-sdk/pull/15362) Allow disabling Cosmovisor logs
## v1.4.0 2022-10-23
### API Breaking Changes

View File

@ -6,20 +6,21 @@ sidebar_position: 1
`cosmovisor` is a small process manager for Cosmos SDK application binaries that monitors the governance module for incoming chain upgrade proposals. If it sees a proposal that gets approved, `cosmovisor` can automatically download the new binary, stop the current binary, switch from the old binary to the new one, and finally restart the node with the new binary.
* [Design](#design)
* [Contributing](#contributing)
* [Setup](#setup)
* [Installation](#installation)
* [Command Line Arguments And Environment Variables](#command-line-arguments-and-environment-variables)
* [Folder Layout](#folder-layout)
* [Usage](#usage)
* [Initialization](#initialization)
* [Detecting Upgrades](#detecting-upgrades)
* [Auto-Download](#auto-download)
* [Example: SimApp Upgrade](#example-simapp-upgrade)
* [Chain Setup](#chain-setup)
* [Prepare Cosmovisor and Start the Chain](#prepare-cosmovisor-and-start-the-chain)
* [Update App](#update-app)
* [Cosmovisor](#cosmovisor)
* [Design](#design)
* [Contributing](#contributing)
* [Setup](#setup)
* [Installation](#installation)
* [Command Line Arguments And Environment Variables](#command-line-arguments-and-environment-variables)
* [Folder Layout](#folder-layout)
* [Usage](#usage)
* [Initialization](#initialization)
* [Detecting Upgrades](#detecting-upgrades)
* [Auto-Download](#auto-download)
* [Example: SimApp Upgrade](#example-simapp-upgrade)
* [Chain Setup](#chain-setup)
* [Prepare Cosmovisor and Start the Chain](#prepare-cosmovisor-and-start-the-chain)
* [Update App](#update-app)
## Design
@ -60,22 +61,11 @@ go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v0.1.0
Run `cosmovisor version` to check the cosmovisor version.
You can also install from source by pulling the cosmos-sdk repository and switching to the correct version and building as follows:
Alternatively, for building from source, simply run `make cosmovisor`. The binary will be located in `tools/cosmovisor`.
```shell
git clone git@github.com:cosmos/cosmos-sdk
cd cosmos-sdk
git checkout cosmovisor/vx.x.x
make cosmovisor
```
This will build cosmovisor in `/cosmovisor` directory. Afterwards you may want to put it into your machine's PATH like as follows:
```shell
cp cosmovisor/cosmovisor ~/go/bin/cosmovisor
```
*Note: If you are using go `v1.15` or earlier, you will need to use `go get`, and you may want to run the command outside a project directory.*
:::warning
Building from source using `make cosmovisor` won't display the correct `cosmovisor` version.
:::
### Command Line Arguments And Environment Variables

View File

@ -0,0 +1,23 @@
package main
import (
"fmt"
"cosmossdk.io/tools/cosmovisor"
"github.com/spf13/cobra"
)
var configCmd = &cobra.Command{
Use: "config",
Short: "Display cosmovisor config (prints environment variables used by cosmovisor).",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := cosmovisor.GetConfigFromEnv()
if err != nil {
return err
}
fmt.Fprint(cmd.OutOrStdout(), cfg.DetailString())
return nil
},
}

View File

@ -16,13 +16,9 @@ import (
"cosmossdk.io/x/upgrade/plan"
)
func init() {
rootCmd.AddCommand(initCmd)
}
var initCmd = &cobra.Command{
Use: "init <path to executable>",
Short: "Initializes a cosmovisor daemon home directory.",
Short: "Initialize a cosmovisor daemon home directory.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
logger := cmd.Context().Value(log.ContextKey).(*zerolog.Logger)

View File

@ -12,7 +12,7 @@ func main() {
logger := log.NewLoggerWithKV(os.Stdout, log.ModuleKey, "cosmovisor")
ctx := context.WithValue(context.Background(), log.ContextKey, logger)
if err := rootCmd.ExecuteContext(ctx); err != nil {
if err := NewRootCmd().ExecuteContext(ctx); err != nil {
cverrors.LogErrors(logger, "", err)
os.Exit(1)
}

View File

@ -4,8 +4,19 @@ import (
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "cosmovisor",
Short: "A process manager for Cosmos SDK application binaries.",
Long: GetHelpText(),
func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "cosmovisor",
Short: "A process manager for Cosmos SDK application binaries.",
Long: GetHelpText(),
}
rootCmd.AddCommand(
initCmd,
runCmd,
configCmd,
NewVersionCmd(),
)
return rootCmd
}

View File

@ -7,10 +7,6 @@ import (
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(runCmd)
}
var runCmd = &cobra.Command{
Use: "run",
Short: "Run an APP command.",

View File

@ -1,4 +0,0 @@
package main
// TODO: Write tests for func Run(args []string) error
// https://github.com/cosmos/cosmos-sdk/issues/11852

View File

@ -9,25 +9,26 @@ import (
"github.com/spf13/cobra"
)
func init() {
versionCmd.Flags().StringP(OutputFlag, "o", "text", "Output format (text|json)")
rootCmd.AddCommand(versionCmd)
}
// OutputFlag defines the output format flag
var OutputFlag = "output"
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version of Cosmovisor.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if val, err := cmd.Flags().GetString(OutputFlag); val == "json" && err == nil {
return printVersionJSON(cmd, args)
}
func NewVersionCmd() *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Short: "Display cosmovisor and APP version.",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if val, err := cmd.Flags().GetString(OutputFlag); val == "json" && err == nil {
return printVersionJSON(cmd, args)
}
return printVersion(cmd, args)
},
return printVersion(cmd, args)
},
}
versionCmd.Flags().StringP(OutputFlag, "o", "text", "Output format (text|json)")
return versionCmd
}
func getVersion() string {

View File

@ -12,6 +12,7 @@ import (
func TestVersionCommand_Error(t *testing.T) {
logger := log.NewTestLogger(t).With(log.ModuleKey, "cosmovisor")
rootCmd := NewRootCmd()
rootCmd.SetArgs([]string{"version"})
out := bytes.NewBufferString("")