-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
693 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.