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: spaceship #103

Merged
merged 25 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions app.ignite.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version: 1
apps:
spaceship:
description: Deploy your chain into a remote server in minutes
path: ./spaceship
explorer:
description: Easy to use terminal chain explorer for testing your Ignite blockchains
path: ./explorer
Expand Down
1 change: 1 addition & 0 deletions go.work.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ use (
./hermes
./appregistry
./rollkit
./spaceship
)
5 changes: 5 additions & 0 deletions spaceship/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Spaceship App Changelog

## [`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
86 changes: 86 additions & 0 deletions spaceship/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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.

## Prerequisites

* Ignite CLI: Version v28.4.0 or higher is required.
* Blockchain Scaffold: A blockchain scaffolded using Ignite

## Usage

Spaceship provides multiple ways to connect to your SSH server for deployment:

```sh
ignite spaceship deploy [email protected] --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 [email protected] --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/<chain-id> and include:

- Binary Directory: $HOME/workspace/<chain-id>/bin - Contains the chain binary.
- Home Directory: $HOME/workspace/<chain-id>/home - Stores chain data.
- Log Directory: $HOME/workspace/<chain-id>/log - Holds logs of the running chain.
- Runner Script: $HOME/workspace/<chain-id>/run.sh - A script to start the binary in the background using nohup.
- PID File: $HOME/workspace/<chain-id>/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 [email protected] --key $HOME/.ssh/id_rsa
```

- View Logs:

```sh
ignite spaceship log [email protected] --key $HOME/.ssh/id_rsa
```

- Restart the Chain:

```sh
ignite spaceship restart [email protected] --key $HOME/.ssh/id_rsa
```

- Stop the Chain:

```sh
ignite spaceship stop [email protected] --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.

### 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/<chain-id>/home.
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:

```
validators:
- name: alice
bonded: '100000000stake'
app:
pruning: "nothing"
config:
moniker: "mychain"
client:
output: "json"
```

For more information, please refer to the [Ignite documentation](https://docs.ignite.com).
84 changes: 84 additions & 0 deletions spaceship/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package cmd

import "github.com/ignite/cli/v28/ignite/services/plugin"

var defaultFlags = []*plugin.Flag{
{
Name: flagUser,
Shorthand: "u",
Usage: "ssh user",
Type: plugin.FlagTypeString,
},
{
Name: flagPort,
Shorthand: "p",
Usage: "ssh port",
Type: plugin.FlagTypeString,
},
{
Name: flagPassword,
Usage: "ssh user password",
Type: plugin.FlagTypeString,
},
{
Name: flagKey,
Shorthand: "k",
Usage: "ssh key",
Type: plugin.FlagTypeString,
},
{
Name: flagRawKey,
Shorthand: "r",
Usage: "ssh raw key",
Type: plugin.FlagTypeString,
},
{
Name: flagKeyPassword,
Usage: "ssh key password",
Type: plugin.FlagTypeString,
},
}

// GetCommands returns the list of spaceship app commands.
func GetCommands() []*plugin.Command {
return []*plugin.Command{
{
Use: "spaceship [command]",
Short: "spaceship is an awesome Ignite application!",
Commands: []*plugin.Command{
{
Use: "deploy",
Short: "deploy your chain",
Flags: append(defaultFlags,
&plugin.Flag{
Name: flagInitChain,
Shorthand: "i",
Usage: "run init chain and create the home folder",
Type: plugin.FlagTypeBool,
},
),
},
{
Use: "log",
Short: "get chain logs if its running",
Flags: defaultFlags,
},
{
Use: "status",
Short: "get chain status if its running",
Flags: defaultFlags,
},
{
Use: "restart",
Short: "restart your chain",
Flags: defaultFlags,
},
{
Use: "stop",
Short: "stop your chain",
Flags: defaultFlags,
},
},
},
}
}
81 changes: 81 additions & 0 deletions spaceship/cmd/debug/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package main

import (
"context"
"fmt"
"os"
"path/filepath"

"github.com/ignite/cli/v28/ignite/services/plugin"

"github.com/ignite/apps/spaceship/cmd"
)

func main() {
home, err := os.UserHomeDir()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
var (
args = os.Args
ctx = context.Background()
chainInfo = &plugin.ChainInfo{
AppPath: filepath.Join(home, "Desktop/go/src/github.com/ignite/mars"),
ChainId: "mars",
}
c = &plugin.ExecutedCommand{
Use: args[1],
Path: "ignite spaceship " + args[1],
Args: []string{fmt.Sprintf("%[email protected]", filepath.Base(home))},
OsArgs: os.Args,
With: nil,
Flags: []*plugin.Flag{
{
Name: "key",
Shorthand: "k",
Usage: "ssh key",
Type: plugin.FlagTypeString,
Value: filepath.Join(home, ".ssh/id_rsa"),
},
{
Name: "init-chain",
Shorthand: "i",
Usage: "run init chain and create the home folder",
Type: plugin.FlagTypeBool,
Value: "true",
},
},
}
)
switch args[1] {
case "deploy":
if err := cmd.ExecuteSSHDeploy(ctx, c, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
case "log":
if err := cmd.ExecuteSSHLog(ctx, c, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
case "status":
if err := cmd.ExecuteSSHStatus(ctx, c, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
case "restart":
if err := cmd.ExecuteSSHRestart(ctx, c, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
case "stop":
if err := cmd.ExecuteSSHSStop(ctx, c, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
default:
fmt.Fprintf(os.Stderr, "unknown command: %s", args[1])
return
}
}
Loading
Loading