From 1d412918743bd99693f60f190e03711d6661d2c0 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 25 Nov 2024 00:16:51 -0300 Subject: [PATCH 1/5] improve the log command --- spaceship/README.md | 20 ++++++++++++ spaceship/cmd/chain.go | 4 +++ spaceship/cmd/cmd.go | 65 +++++++++++++++++-------------------- spaceship/cmd/debug/main.go | 41 +++++++++++++---------- spaceship/cmd/faucet.go | 5 +++ spaceship/cmd/log.go | 20 +++++++----- spaceship/cmd/ssh.go | 5 --- spaceship/main.go | 9 +---- spaceship/pkg/ssh/log.go | 24 ++++++++++++-- 9 files changed, 116 insertions(+), 77 deletions(-) diff --git a/spaceship/README.md b/spaceship/README.md index d1165e12..5417b8e8 100644 --- a/spaceship/README.md +++ b/spaceship/README.md @@ -66,6 +66,26 @@ ignite spaceship stop root@127.0.0.1 --key $HOME/.ssh/id_rsa To redeploy the chain on the same server without overwriting the home directory, use the `--init-chain` flag to reinitialize the chain if necessary. +## Faucet + +You can deploy your chain along with a faucet application passing the faucet flag to the deploy command + +```ssh +ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet +``` + +and also specify the faucet port: + +```ssh +ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet --faucet-port 8077 +``` + +To check the faucet logs, pass the parameter `faucet` to the `--app` flag into the log command: + +```sh +ignite spaceship log root@127.0.0.1 --key $HOME/.ssh/id_rsa --app faucet +``` + ### Config You can override the default [chain configuration](https://docs.ignite.com/references/config#validators) by using the diff --git a/spaceship/cmd/chain.go b/spaceship/cmd/chain.go index 7bf34d8a..491ba7ba 100644 --- a/spaceship/cmd/chain.go +++ b/spaceship/cmd/chain.go @@ -20,6 +20,10 @@ import ( "github.com/ignite/apps/spaceship/templates/script" ) +const ( + flagInitChain = "init-chain" +) + // ExecuteSSHStatus executes the ssh status subcommand. func ExecuteSSHStatus(ctx context.Context, cmd *plugin.ExecutedCommand, chain *plugin.ChainInfo) error { session := cliui.New(cliui.StartSpinnerWithText(statusConnecting)) diff --git a/spaceship/cmd/cmd.go b/spaceship/cmd/cmd.go index 0189f90c..23cbaa8c 100644 --- a/spaceship/cmd/cmd.go +++ b/spaceship/cmd/cmd.go @@ -1,6 +1,13 @@ package cmd -import "github.com/ignite/cli/v28/ignite/services/plugin" +import ( + "fmt" + "strings" + + "github.com/ignite/cli/v28/ignite/services/plugin" + + "github.com/ignite/apps/spaceship/pkg/ssh" +) var defaultFlags = []*plugin.Flag{ { @@ -73,44 +80,30 @@ func GetCommands() []*plugin.Command { { Use: "log [host]", Short: "get remote logs", - Commands: []*plugin.Command{ - { - Use: "chain", - Short: "get chain logs if its running", - Flags: append(defaultFlags, - &plugin.Flag{ - Name: flagLines, - Shorthand: "l", - Usage: "number of lines of chain logs", - Type: plugin.FlagTypeInt, - DefaultValue: "100", - }, - &plugin.Flag{ - Name: flagRealTime, - Usage: "show the logs in the real time", - Type: plugin.FlagTypeBool, - }, - ), + Flags: append(defaultFlags, + &plugin.Flag{ + Name: flagLines, + Shorthand: "l", + Usage: "number of lines of chain logs", + Type: plugin.FlagTypeInt, + DefaultValue: "100", }, - { - Use: "faucet", - Short: "get faucet logs if its running", - Flags: append(defaultFlags, - &plugin.Flag{ - Name: flagLines, - Shorthand: "l", - Usage: "number of lines of chain logs", - Type: plugin.FlagTypeInt, - DefaultValue: "100", - }, - &plugin.Flag{ - Name: flagRealTime, - Usage: "show the logs in the real time", - Type: plugin.FlagTypeBool, - }, + &plugin.Flag{ + Name: flagRealTime, + Usage: "show the logs in the real time", + Type: plugin.FlagTypeBool, + }, + &plugin.Flag{ + Name: flagAppLog, + Shorthand: "a", + Usage: fmt.Sprintf( + "the app to show the log (%s)", + strings.Join(ssh.LogTypes(), ","), ), + Type: plugin.FlagTypeString, + DefaultValue: ssh.LogChain.String(), }, - }, + ), }, { Use: "status [host]", diff --git a/spaceship/cmd/debug/main.go b/spaceship/cmd/debug/main.go index 4fd7c4f6..c85b0cd7 100644 --- a/spaceship/cmd/debug/main.go +++ b/spaceship/cmd/debug/main.go @@ -5,10 +5,12 @@ import ( "fmt" "os" "path/filepath" + "strings" "github.com/ignite/cli/v28/ignite/services/plugin" "github.com/ignite/apps/spaceship/cmd" + "github.com/ignite/apps/spaceship/pkg/ssh" ) func main() { @@ -72,24 +74,27 @@ func main() { return } case "log": - c.Flags = append(c.Flags, &plugin.Flag{ - Name: "real-time", - Usage: "show the logs in the real time", - Type: plugin.FlagTypeBool, - Value: "true", - }) - switch args[2] { - case "chain": - if err := cmd.ExecuteChainSSHLog(ctx, c, chainInfo); err != nil { - fmt.Fprintln(os.Stderr, err) - return - } - case "faucet": - if err := cmd.ExecuteFaucetSSHLog(ctx, c, chainInfo); err != nil { - fmt.Fprintln(os.Stderr, err) - return - } - fmt.Fprintf(os.Stderr, "unknown log command: %s", args[2]) + c.Flags = append(c.Flags, + &plugin.Flag{ + Name: "real-time", + Usage: "show the logs in the real time", + Type: plugin.FlagTypeBool, + Value: "true", + }, + &plugin.Flag{ + Name: "app", + Shorthand: "a", + Usage: fmt.Sprintf( + "the app to show the log (%s)", + strings.Join(ssh.LogTypes(), ","), + ), + Type: plugin.FlagTypeString, + DefaultValue: ssh.LogChain.String(), + Value: ssh.LogChain.String(), + }, + ) + if err := cmd.ExecuteSSHLog(ctx, c, chainInfo); err != nil { + fmt.Fprintln(os.Stderr, err) return } case "status": diff --git a/spaceship/cmd/faucet.go b/spaceship/cmd/faucet.go index a63a4b13..efe73e9c 100644 --- a/spaceship/cmd/faucet.go +++ b/spaceship/cmd/faucet.go @@ -9,6 +9,11 @@ import ( "github.com/ignite/cli/v28/ignite/services/plugin" ) +const ( + flagFaucet = "faucet" + flagFaucetPort = "faucet-port" +) + func faucetPort(f []*plugin.Flag) (uint64, error) { flags := plugin.Flags(f) port, err := flags.GetUint64(flagFaucetPort) diff --git a/spaceship/cmd/log.go b/spaceship/cmd/log.go index 6a5f33bd..bbcef1bc 100644 --- a/spaceship/cmd/log.go +++ b/spaceship/cmd/log.go @@ -11,16 +11,14 @@ import ( "github.com/ignite/apps/spaceship/pkg/ssh" ) -func ExecuteChainSSHLog(ctx context.Context, cmd *plugin.ExecutedCommand, chain *plugin.ChainInfo) error { - return ExecuteSSHLog(ctx, ssh.LogChain, cmd, chain) -} - -func ExecuteFaucetSSHLog(ctx context.Context, cmd *plugin.ExecutedCommand, chain *plugin.ChainInfo) error { - return ExecuteSSHLog(ctx, ssh.LogFaucet, cmd, chain) -} +const ( + flagLines = "lines" + flagRealTime = "real-time" + flagAppLog = "app" +) // ExecuteSSHLog executes the ssh log subcommand. -func ExecuteSSHLog(ctx context.Context, logType ssh.LogType, cmd *plugin.ExecutedCommand, chain *plugin.ChainInfo) error { +func ExecuteSSHLog(ctx context.Context, cmd *plugin.ExecutedCommand, chain *plugin.ChainInfo) error { session := cliui.New(cliui.StartSpinnerWithText(statusConnecting)) defer session.End() @@ -28,8 +26,14 @@ func ExecuteSSHLog(ctx context.Context, logType ssh.LogType, cmd *plugin.Execute flags = plugin.Flags(cmd.Flags) lines, _ = flags.GetInt(flagLines) realTime, _ = flags.GetBool(flagRealTime) + appLog, _ = flags.GetString(flagAppLog) ) + logType, err := ssh.ParseLogType(appLog) + if err != nil { + return err + } + c, err := executeSSH(cmd, chain) if err != nil { return err diff --git a/spaceship/cmd/ssh.go b/spaceship/cmd/ssh.go index 11b7ca6c..2f49de21 100644 --- a/spaceship/cmd/ssh.go +++ b/spaceship/cmd/ssh.go @@ -16,11 +16,6 @@ const ( flagKey = "key" flagRawKey = "raw-key" flagKeyPassword = "key-password" - flagInitChain = "init-chain" - flagFaucet = "faucet" - flagFaucetPort = "faucet-port" - flagLines = "lines" - flagRealTime = "real-time" statusConnecting = "Connecting..." ) diff --git a/spaceship/main.go b/spaceship/main.go index 7b4d8edd..88db5020 100644 --- a/spaceship/main.go +++ b/spaceship/main.go @@ -38,14 +38,7 @@ func (app) Execute(ctx context.Context, c *plugin.ExecutedCommand, api plugin.Cl case "stop": return cmd.ExecuteSSHSStop(ctx, c, chainInfo) case "log": - switch args[1] { - case "chain": - return cmd.ExecuteChainSSHLog(ctx, c, chainInfo) - case "faucet": - return cmd.ExecuteFaucetSSHLog(ctx, c, chainInfo) - default: - return fmt.Errorf("unknown log command: %s", args[1]) - } + return cmd.ExecuteSSHLog(ctx, c, chainInfo) case "faucet": switch args[1] { case "status": diff --git a/spaceship/pkg/ssh/log.go b/spaceship/pkg/ssh/log.go index 1be0f945..8f32e7bc 100644 --- a/spaceship/pkg/ssh/log.go +++ b/spaceship/pkg/ssh/log.go @@ -30,10 +30,30 @@ type ( const ( logExtension = ".log" - LogChain LogType = "chain_" - LogFaucet LogType = "faucet_" + LogChain LogType = "chain" + LogFaucet LogType = "faucet" ) +func (l LogType) String() string { + return string(l) +} + +func LogTypes() []string { + return []string{LogChain.String(), LogFaucet.String()} +} + +// ParseLogType parses the log type from a string. +func ParseLogType(logType string) (LogType, error) { + switch LogType(strings.ToLower(logType)) { + case LogChain: + return LogChain, nil + case LogFaucet: + return LogFaucet, nil + default: + return "", errors.New("invalid log type: " + logType) + } +} + func (a logs) Len() int { return len(a) } func (a logs) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a logs) Less(i, j int) bool { return a[i].time.Before(a[j].time) } From e7b134deb7f5e299f4a66a840eef399689fc1a19 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 25 Nov 2024 00:26:25 -0300 Subject: [PATCH 2/5] improve readme --- spaceship/README.md | 95 +++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 55 deletions(-) diff --git a/spaceship/README.md b/spaceship/README.md index 5417b8e8..2f8cfd1c 100644 --- a/spaceship/README.md +++ b/spaceship/README.md @@ -1,12 +1,11 @@ # Spaceship -Spaceship is an Ignite App designed to extend the [Ignite CLI](https://github.com/ignite/cli) by providing tools to -deploy blockchain applications via SSH. +Spaceship is an Ignite App designed to extend the [Ignite CLI](https://github.com/ignite/cli) by providing tools to deploy blockchain applications via SSH. ## Prerequisites -* Ignite CLI: Version `v28.4.0` or higher is required. -* Blockchain Scaffold: A blockchain scaffolded using Ignite +* **Ignite CLI**: Version `v28.4.0` or higher is required. +* **Blockchain Scaffold**: A blockchain scaffolded using Ignite. ## Usage @@ -19,68 +18,57 @@ ignite spaceship deploy 127.0.0.1 --user root --password password ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --key-password key_password ``` -Each command initiates a build of the blockchain binary and sets up the chain's home directory based on the -configuration. The app then connects to the specified SSH server, establishes workspaces, transfers the binary, and -executes it using a runner script. The workspaces are organized under `$HOME/workspace/` and include: +Each command initiates a build of the blockchain binary and sets up the chain's home directory based on the configuration. The app then connects to the specified SSH server, establishes workspaces, transfers the binary, and executes it using a runner script. -- Binary Directory: `$HOME/workspace//bin` - Contains the chain binary. -- Home Directory: `$HOME/workspace//home` - Stores chain data. -- Log Directory: `$HOME/workspace//log` - Holds logs of the running chain. -- Runner Script: `$HOME/workspace//run.sh` - A script to start the binary in the background using nohup. -- PID File: `$HOME/workspace//spaceship.pid` - Stores the PID of the currently running chain instance. +The workspaces are organized under `$HOME/workspace/` and include: +- **Binary Directory**: `$HOME/workspace//bin` - Contains the chain binary. +- **Home Directory**: `$HOME/workspace//home` - Stores chain data. +- **Log Directory**: `$HOME/workspace//log` - Holds logs of the running chain. +- **Runner Script**: `$HOME/workspace//run.sh` - A script to start the binary in the background using `nohup`. +- **PID File**: `$HOME/workspace//spaceship.pid` - Stores the PID of the currently running chain instance. ### Managing the Chain To manage your blockchain deployment, use the following commands: -- Check status: - -```sh -ignite spaceship status root@127.0.0.1 --key $HOME/.ssh/id_rsa -``` - -- View logs: - -```sh -ignite spaceship log root@127.0.0.1 --key $HOME/.ssh/id_rsa -``` - -- Watch the logs in real time: - -```sh -ignite spaceship log root@127.0.0.1 --key $HOME/.ssh/id_rsa --real-time -``` - -- Restart the chain: - -```sh -ignite spaceship restart root@127.0.0.1 --key $HOME/.ssh/id_rsa -``` - -- Stop the Chain: - -```sh -ignite spaceship stop root@127.0.0.1 --key $HOME/.ssh/id_rsa -``` - -To redeploy the chain on the same server without overwriting the home directory, use the `--init-chain` flag to -reinitialize the chain if necessary. +- **Check status**: + ```sh + ignite spaceship status root@ --key $HOME/.ssh/id_rsa + ``` +- **View logs**: + ```sh + ignite spaceship log root@ --key $HOME/.ssh/id_rsa + ``` +- **Watch the logs in real time**: + ```sh + ignite spaceship log root@ --key $HOME/.ssh/id_rsa --real-time + ``` +- **Restart the chain**: + ```sh + ignite spaceship restart root@ --key $HOME/.ssh/id_rsa + ``` +- **Stop the chain**: + ```sh + ignite spaceship stop root@ --key $HOME/.ssh/id_rsa + ``` + +To redeploy the chain on the same server without overwriting the home directory, use the `--init-chain` flag to reinitialize the chain if necessary. ## Faucet -You can deploy your chain along with a faucet application passing the faucet flag to the deploy command +You can deploy your chain along with a faucet application by passing the faucet flag to the deploy command: ```ssh ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet ``` -and also specify the faucet port: +You can also specify the faucet port: ```ssh ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet --faucet-port 8077 ``` -To check the faucet logs, pass the parameter `faucet` to the `--app` flag into the log command: +To check the faucet logs, pass the parameter `faucet` to the `--app` flag in the log command: ```sh ignite spaceship log root@127.0.0.1 --key $HOME/.ssh/id_rsa --app faucet @@ -88,16 +76,13 @@ ignite spaceship log root@127.0.0.1 --key $HOME/.ssh/id_rsa --app faucet ### Config -You can override the default [chain configuration](https://docs.ignite.com/references/config#validators) by using the -Ignite configuration file. Validators' node configuration files are stored in the data directory. By default, Spaceship -initializes the chain locally in a temporary folder using the Ignite config file and then copies the configuration to -the remote machine at `$HOME/workspace//home`. -Configuration resets are performed by Ignite when necessary, especially when using the `--init-chain` flag or if the chain -was not previously initialized. +You can override the default [chain configuration](https://docs.ignite.com/references/config#validators) by using the Ignite configuration file. Validators' node configuration files are stored in the data directory. By default, Spaceship initializes the chain locally in a temporary folder using the Ignite config file and then copies the configuration to the remote machine at `$HOME/workspace//home`. -Example Ignite config: +Configuration resets are performed by Ignite when necessary, especially when using the `--init-chain` flag or if the chain was not previously initialized. -``` +**Example Ignite config**: + +```yaml validators: - name: alice bonded: '100000000stake' From 70831751eddb970d65068d98d06d16569137ac57 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 25 Nov 2024 00:36:58 -0300 Subject: [PATCH 3/5] improve readme --- spaceship/README.md | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/spaceship/README.md b/spaceship/README.md index 2f8cfd1c..0c40da61 100644 --- a/spaceship/README.md +++ b/spaceship/README.md @@ -32,25 +32,34 @@ The workspaces are organized under `$HOME/workspace/` and include: To manage your blockchain deployment, use the following commands: - **Check status**: - ```sh - ignite spaceship status root@ --key $HOME/.ssh/id_rsa - ``` + +```sh +ignite spaceship status root@ --key $HOME/.ssh/id_rsa +``` + - **View logs**: - ```sh - ignite spaceship log root@ --key $HOME/.ssh/id_rsa - ``` + +```sh +ignite spaceship log root@ --key $HOME/.ssh/id_rsa +``` + - **Watch the logs in real time**: - ```sh - ignite spaceship log root@ --key $HOME/.ssh/id_rsa --real-time - ``` + +```sh +ignite spaceship log root@ --key $HOME/.ssh/id_rsa --real-time +``` + - **Restart the chain**: - ```sh - ignite spaceship restart root@ --key $HOME/.ssh/id_rsa - ``` + +```sh +ignite spaceship restart root@ --key $HOME/.ssh/id_rsa +``` + - **Stop the chain**: - ```sh - ignite spaceship stop root@ --key $HOME/.ssh/id_rsa - ``` + +```sh +ignite spaceship stop root@ --key $HOME/.ssh/id_rsa +``` To redeploy the chain on the same server without overwriting the home directory, use the `--init-chain` flag to reinitialize the chain if necessary. @@ -58,13 +67,13 @@ To redeploy the chain on the same server without overwriting the home directory, You can deploy your chain along with a faucet application by passing the faucet flag to the deploy command: -```ssh +```sh ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet ``` You can also specify the faucet port: -```ssh +```sh ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet --faucet-port 8077 ``` From 9b24bf0fe351bd6f466a4c1f7c85c6779e0af48a Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 25 Nov 2024 00:40:18 -0300 Subject: [PATCH 4/5] add changelog --- spaceship/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spaceship/CHANGELOG.md b/spaceship/CHANGELOG.md index 9d4594a3..faf2747c 100644 --- a/spaceship/CHANGELOG.md +++ b/spaceship/CHANGELOG.md @@ -1,5 +1,10 @@ # Spaceship App Changelog +## [`v0.1.1`](https://github.com/ignite/apps/releases/tag/spaceship/v0.1.1) + +* [#144](https://github.com/ignite/apps/pull/144) Spaceship faucet +* [#145](https://github.com/ignite/apps/pull/145) Improve logs + ## [`v0.1.0`](https://github.com/ignite/apps/releases/tag/spaceship/v0.1.0) * First release of the Spaceship app compatible with Ignite >= v28.x.y From 3fc164533ad84cefd5acae4f845624a094678639 Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Mon, 25 Nov 2024 00:46:19 -0300 Subject: [PATCH 5/5] improve readme readbilitty --- spaceship/README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spaceship/README.md b/spaceship/README.md index 0c40da61..8443ad20 100644 --- a/spaceship/README.md +++ b/spaceship/README.md @@ -12,10 +12,10 @@ Spaceship is an Ignite App designed to extend the [Ignite CLI](https://github.co Spaceship provides multiple ways to connect to your SSH server for deployment: ```sh -ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa -ignite spaceship deploy 127.0.0.1 --user root --key $HOME/.ssh/id_rsa -ignite spaceship deploy 127.0.0.1 --user root --password password -ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --key-password key_password +ignite spaceship deploy @ --key $HOME/.ssh/id_rsa +ignite spaceship deploy --user root --key $HOME/.ssh/id_rsa +ignite spaceship deploy --user root --password password +ignite spaceship deploy @ --key $HOME/.ssh/id_rsa --key-password key_password ``` Each command initiates a build of the blockchain binary and sets up the chain's home directory based on the configuration. The app then connects to the specified SSH server, establishes workspaces, transfers the binary, and executes it using a runner script. @@ -34,31 +34,31 @@ To manage your blockchain deployment, use the following commands: - **Check status**: ```sh -ignite spaceship status root@ --key $HOME/.ssh/id_rsa +ignite spaceship status @ --key $HOME/.ssh/id_rsa ``` - **View logs**: ```sh -ignite spaceship log root@ --key $HOME/.ssh/id_rsa +ignite spaceship log @ --key $HOME/.ssh/id_rsa ``` - **Watch the logs in real time**: ```sh -ignite spaceship log root@ --key $HOME/.ssh/id_rsa --real-time +ignite spaceship log @ --key $HOME/.ssh/id_rsa --real-time ``` - **Restart the chain**: ```sh -ignite spaceship restart root@ --key $HOME/.ssh/id_rsa +ignite spaceship restart @ --key $HOME/.ssh/id_rsa ``` - **Stop the chain**: ```sh -ignite spaceship stop root@ --key $HOME/.ssh/id_rsa +ignite spaceship stop @ --key $HOME/.ssh/id_rsa ``` To redeploy the chain on the same server without overwriting the home directory, use the `--init-chain` flag to reinitialize the chain if necessary. @@ -68,19 +68,19 @@ To redeploy the chain on the same server without overwriting the home directory, You can deploy your chain along with a faucet application by passing the faucet flag to the deploy command: ```sh -ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet +ignite spaceship deploy @ --key $HOME/.ssh/id_rsa --faucet ``` You can also specify the faucet port: ```sh -ignite spaceship deploy root@127.0.0.1 --key $HOME/.ssh/id_rsa --faucet --faucet-port 8077 +ignite spaceship deploy @ --key $HOME/.ssh/id_rsa --faucet --faucet-port 8077 ``` To check the faucet logs, pass the parameter `faucet` to the `--app` flag in the log command: ```sh -ignite spaceship log root@127.0.0.1 --key $HOME/.ssh/id_rsa --app faucet +ignite spaceship log @ --key $HOME/.ssh/id_rsa --app faucet ``` ### Config