Skip to content

Commit

Permalink
add shh deploy and dev logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Jul 16, 2024
1 parent ab2d831 commit 1d85cfa
Show file tree
Hide file tree
Showing 7 changed files with 693 additions and 78 deletions.
14 changes: 12 additions & 2 deletions spaceship/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ func GetCommands() []*plugin.Command {
Short: "spaceship is an awesome Ignite application!",
Commands: []*plugin.Command{
{
Use: "hello",
Short: "Say hello to the world of ignite!",
Use: "ssh",
Short: "deploy your chain trough ssh",
Commands: []*plugin.Command{
{
Use: "dev",
Short: "deploy your chain into a development mode",
},
{
Use: "deploy",
Short: "deploy your chain into a production mode",
},
},
},
},
},
Expand Down
54 changes: 54 additions & 0 deletions spaceship/cmd/debug/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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",
}
)
switch args[1] {
case "aws":
if err := cmd.ExecuteAWS(ctx, nil); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
case "ssh":
switch args[2] {
case "dev":
if err := cmd.ExecuteSSHDevelopment(ctx, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
case "prod":
if err := cmd.ExecuteSSHDeploy(ctx, chainInfo); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
default:
fmt.Fprintf(os.Stderr, "unknown ssh command: %s", args[2])
return
}
default:
fmt.Fprintf(os.Stderr, "unknown command: %s", args[1])
return
}
}
77 changes: 72 additions & 5 deletions spaceship/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,98 @@ package cmd

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

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

"github.com/ignite/apps/spaceship/pkg/ssh"
)

// ExecuteSSH executes the ssh deploy subcommand.
func ExecuteSSH(ctx context.Context, cmd *plugin.ExecutedCommand) error {
func ExecuteSSHDevelopment(ctx context.Context, chain *plugin.ChainInfo) error {
var (
host = "127.0.0.1" // arg host or URI
user = "danilopantani" // flag user
host = "[email protected]" // arg host or URI
key = "/Users/danilopantani/.ssh/id_rsa" // flag key
// user = "danilopantani" // flag user
// password = "" // flag password
// port = "22" // flag port
// keyPassword = args[5] // flag key password
// keyRaw = args[6] // flag key raw
args = []string{"chain", "build"} // arg ignite cmd
)

c, err := ssh.New(host, ssh.WithUser(user), ssh.WithKey(key))
c, err := ssh.New(host, ssh.WithKey(key), ssh.WithWorkspace(chain.ChainId))
if err != nil {
return err
}
if err := c.Connect(ctx); err != nil {
return err
}
defer c.Close()

srcPath, err := c.UploadSource(ctx, chain.AppPath)
if err != nil {
return err
}

args = append(args, "-p", srcPath)
out, err := c.RunIgniteCommand(ctx, args...)
if err != nil {
return err
}

fmt.Println(out)
return nil
}

// ExecuteSSHDeploy executes the ssh deploy subcommand.
func ExecuteSSHDeploy(ctx context.Context, chain *plugin.ChainInfo) error {
// args := os.Args[2:]
var (
host = "[email protected]" // arg host or URI
key = "/Users/danilopantani/.ssh/id_rsa" // flag key
// user = "danilopantani" // flag user
// password = "" // flag password
// port = "22" // flag port
// keyPassword = args[5] // flag key password
// keyRaw = args[6] // flag key raw

localDir = filepath.Join(os.TempDir(), "spaceship")
binOutput = filepath.Join(localDir, "bin")
chainBin = fmt.Sprintf("%s/%sd", binOutput, chain.ChainId)
chainHome = filepath.Join(localDir, "home")
)

// we are using the ignite chain build command to build the app.
igniteChainBuildCmd := ignitecmd.NewChainBuild()
igniteChainBuildCmd.SetArgs([]string{"-p", chain.AppPath, "-o", binOutput, "-y"})
if err := igniteChainBuildCmd.ExecuteContext(ctx); err != nil {
return err
}

// init the chain
igniteChainInitCmd := ignitecmd.NewChainInit()
igniteChainInitCmd.SetArgs([]string{"-p", chain.AppPath, "-h", chainHome, "-y"})
if err := igniteChainInitCmd.ExecuteContext(ctx); err != nil {
return err
}

c, err := ssh.New(host, ssh.WithKey(key))
if err != nil {
return err
}
if err := c.Connect(ctx); err != nil {
return err
}
defer c.Close()

binPath, err := c.UploadBinary(ctx, chainBin)
if err != nil {
return err
}

fmt.Println(binPath)
return nil
}
62 changes: 61 additions & 1 deletion spaceship/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/melbahja/goph v1.4.0
github.com/pkg/sftp v1.13.6
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.7.0
)

require (
Expand All @@ -26,21 +27,33 @@ require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
github.com/AlecAivazis/survey/v2 v2.3.7 // indirect
github.com/DataDog/datadog-go v3.2.0+incompatible // indirect
github.com/DataDog/zstd v1.5.5 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/alecthomas/chroma v0.8.2 // indirect
github.com/atotto/clipboard v0.1.2 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.1-0.20220910012023-760eaf8b6816 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/calmh/randomart v1.1.0 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/bubbles v0.7.6 // indirect
github.com/charmbracelet/bubbletea v0.23.2 // indirect
github.com/charmbracelet/charm v0.8.6 // indirect
github.com/charmbracelet/glamour v0.2.1-0.20210402234443-abe9cda419ba // indirect
github.com/charmbracelet/glow v1.4.1 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/cilium/ebpf v0.9.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cockroachdb/errors v1.11.1 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
Expand All @@ -49,6 +62,9 @@ require (
github.com/cockroachdb/tokenbucket v0.0.0-20230807174530-cc333fc44b06 // indirect
github.com/cometbft/cometbft v0.38.6 // indirect
github.com/cometbft/cometbft-db v0.9.1 // indirect
github.com/containerd/console v1.0.4-0.20230508195404-8d3c090fd31c // indirect
github.com/containerd/containerd v1.7.11 // indirect
github.com/cosiner/argv v0.1.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-db v1.0.2 // indirect
github.com/cosmos/cosmos-proto v1.0.0-beta.5 // indirect
Expand All @@ -61,21 +77,30 @@ require (
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/derekparker/trie v0.0.0-20221213183930-4c74548207f4 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dlclark/regexp2 v1.2.0 // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/dvsekhvalnov/jose2go v1.6.0 // indirect
github.com/emicklei/dot v1.6.1 // indirect
github.com/emicklei/proto v1.12.2 // indirect
github.com/emicklei/proto-contrib v0.15.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/getsentry/sentry-go v0.27.0 // indirect
github.com/go-delve/delve v1.21.0 // indirect
github.com/go-delve/liner v1.2.3-0.20220127212407-d32d89dd2a5d // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
Expand All @@ -102,11 +127,15 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-dap v0.9.1 // indirect
github.com/google/go-github/v48 v48.2.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/gorilla/rpc v1.2.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
Expand All @@ -120,11 +149,15 @@ require (
github.com/hdevalence/ed25519consensus v0.1.0 // indirect
github.com/huandu/skiplist v1.2.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/ignite/ignite-files/nodetime v0.0.4 // indirect
github.com/ignite/ignite-files/protoc v0.0.1 // indirect
github.com/ignite/web v0.6.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/improbable-eng/grpc-web v0.15.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.7 // indirect
github.com/kr/fs v0.1.0 // indirect
Expand All @@ -134,18 +167,37 @@ require (
github.com/linxGnu/grocksdb v1.8.14 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/meowgorithm/babyenv v1.3.1 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/moby v24.0.9+incompatible // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/gitcha v0.2.0 // indirect
github.com/muesli/go-app-paths v0.2.1 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/sasquatch v0.0.0-20200811221207-66979d92330a // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/nqd/flat v0.2.0 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/runc v1.1.12 // indirect
github.com/otiai10/copy v1.14.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
Expand All @@ -155,14 +207,18 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.2 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/radovskyb/watcher v1.0.7 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/rs/zerolog v1.32.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20180611051255-d3107576ba94 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/segmentio/ksuid v1.0.3 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
Expand All @@ -179,15 +235,19 @@ require (
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/yuin/goldmark v1.4.13 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
go.starlark.net v0.0.0-20220816155156-cfacd8902214 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/arch v0.0.0-20190927153633-4e8777c89be4 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
Expand Down
Loading

0 comments on commit 1d85cfa

Please sign in to comment.