Skip to content

Commit

Permalink
Merge pull request #314 from ubclaunchpad/client/#260-inertia-remove
Browse files Browse the repository at this point in the history
inertia [remote] remove
  • Loading branch information
bobheadxi committed Jul 11, 2018
2 parents 49bd5e2 + edf5de2 commit 696e3ff
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 33 deletions.
15 changes: 15 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ func (c *Client) DaemonDown() error {
return nil
}

// InertiaDown removes the inertia/ directory on the remote instance
func (c *Client) InertiaDown() error {
scriptBytes, err := internal.Asset("client/scripts/inertia-down.sh")
if err != nil {
return err
}

_, stderr, err := c.sshRunner.Run(string(scriptBytes))
if err != nil {
return fmt.Errorf("Inertia down failed: %s: %s", err.Error(), stderr.String())
}

return nil
}

// installDocker installs docker on a remote vps.
func (c *Client) installDocker(session SSHSession) error {
installDockerSh, err := internal.Asset("client/scripts/docker.sh")
Expand Down
57 changes: 40 additions & 17 deletions client/internal/compiled.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion client/scripts/daemon-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ DAEMON_NAME=inertia-daemon

# Get daemon container and take it down if it is running.
ALREADY_RUNNING=`sudo docker ps -q --filter "name=$DAEMON_NAME"`
sudo docker rm -f $ALREADY_RUNNING
if [ ! -z "$ALREADY_RUNNING" ]; then
sudo docker rm -f $ALREADY_RUNNING
fi;
8 changes: 8 additions & 0 deletions client/scripts/inertia-down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

# Basic script for bringing down Inertia.

set -e

# Remove Inertia from VPS
rm -rf ~/inertia/
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var cmdSetConfigProperty = &cobra.Command{
Use: "set [PROPERTY] [VALUE]",
Short: "Set configuration property of the project",
Long: `Set configuration property of the project. This will modify local toml file.`,
Args: cobra.MinimumNArgs(2),
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
// Ensure project initialized.
config, path, err := local.GetProjectConfigFromDisk(configFilePath)
Expand Down
40 changes: 39 additions & 1 deletion cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Run 'inertia [REMOTE] init' to gather this information.`,
reset := deepCopy(cmdDeploymentReset)
cmd.AddCommand(reset)

remove := deepCopy(cmdDeploymentRemove)
cmd.AddCommand(remove)

// Attach a "short" option on all commands
cmd.PersistentFlags().BoolP(
"short", "s", false,
Expand Down Expand Up @@ -362,7 +365,7 @@ var cmdDeploymentSendFile = &cobra.Command{
Short: "Send a file to your Inertia deployment",
Long: `Send a file, such as a configuration or .env file, to your Inertia
deployment. Provide a relative path to your file.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
remoteName := strings.Split(cmd.Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
Expand Down Expand Up @@ -474,3 +477,38 @@ running 'inertia [REMOTE] init'`,
}
},
}

var cmdDeploymentRemove = &cobra.Command{
Use: "remove",
Short: "Remove Inertia and shutdown the daemon in the remote VPS",
Long: `Remove Inertia directory (~/inertia) and takes down the
daemon image from the VPS.`,
Run: func(cmd *cobra.Command, args []string) {
println("WARNING: This will remove Inertia from the remote")
println("as well as take the daemon and is irreversible. Continue? (y/n)")
var response string
_, err := fmt.Scanln(&response)
if err != nil || response != "y" {
log.Fatal("aborting")
}

// Daemon down
remoteName := strings.Split(cmd.Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
if err != nil {
log.Fatal(err)
}
println("Stopping daemon...")
err = deployment.DaemonDown()
if err != nil {
log.Fatal(err)
}
println("Removing Inertia directories...")
err = deployment.InertiaDown()
if err != nil {
log.Fatal(err)
}

println("Inertia and related daemon removed.")
},
}
4 changes: 2 additions & 2 deletions cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var cmdDeploymentEnvSet = &cobra.Command{
Short: "Set an environment variable on your remote",
Long: `Set a persistent environment variable on your remote. Set environment
variables are applied to all deployed containers.`,
Args: cobra.MinimumNArgs(2),
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
remoteName := strings.Split(cmd.Parent().Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
Expand Down Expand Up @@ -52,7 +52,7 @@ var cmdDeploymentEnvRemove = &cobra.Command{
Short: "Remove an environment variable from your remote",
Long: `Remove the specified environment variable from deployed containers
and persistent environment storage.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
remoteName := strings.Split(cmd.Parent().Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
Expand Down
11 changes: 7 additions & 4 deletions cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var cmdProvisionECS = &cobra.Command{
Long: `[BETA] Provision a new Amazon EC2 instance and set it up for continuous deployment
with Inertia. Make sure you run this command with the '-p' flag to indicate what ports
your project uses, since they must be exposed on your new instance.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Ensure project initialized.
config, path, err := local.GetProjectConfigFromDisk(configFilePath)
Expand All @@ -67,11 +67,14 @@ var cmdProvisionECS = &cobra.Command{
log.Fatal(err)
}
prov, err = provision.NewEC2Provisioner(id, key, os.Stdout)
if err != nil {
log.Fatal(err)
}
} else {
prov, err = provision.NewEC2ProvisionerFromEnv(os.Stdout)
}
if err != nil {
log.Fatal(err)
if err != nil {
log.Fatal(err)
}
}

// Report connected user
Expand Down
8 changes: 4 additions & 4 deletions cmd/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var cmdAddRemote = &cobra.Command{
Long: `Add a reference to a remote VPS instance. Requires
information about the VPS including IP address, user and a PEM
file. Specify a VPS name.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Ensure project initialized.
config, path, err := local.GetProjectConfigFromDisk(configFilePath)
Expand Down Expand Up @@ -107,7 +107,7 @@ var cmdRemoveRemote = &cobra.Command{
Use: "rm [REMOTE]",
Short: "Remove a remote.",
Long: `Remove a remote from Inertia's configuration file.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
config, path, err := local.GetProjectConfigFromDisk(configFilePath)
if err != nil {
Expand All @@ -132,7 +132,7 @@ var cmdShowRemote = &cobra.Command{
Use: "show [REMOTE]",
Short: "Show details about remote.",
Long: `Show details about the given remote.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// Ensure project initialized.
config, _, err := local.GetProjectConfigFromDisk(configFilePath)
Expand All @@ -153,7 +153,7 @@ var cmdSetRemoteProperty = &cobra.Command{
Use: "set [REMOTE] [PROPERTY] [VALUE]",
Short: "Set details about remote.",
Long: `Set details about the given remote.`,
Args: cobra.MinimumNArgs(3),
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
// Ensure project initialized.
config, path, err := local.GetProjectConfigFromDisk(configFilePath)
Expand Down
5 changes: 2 additions & 3 deletions cmd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This user will be able to log in and view or configure the
deployment from the web app.
Use the --admin flag to create an admin user.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
remoteName := strings.Split(cmd.Parent().Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
Expand Down Expand Up @@ -77,7 +77,7 @@ var cmdDeploymentRemoveUser = &cobra.Command{
This user will no longer be able to log in and view or configure the
deployment from the web app.`,
Args: cobra.MinimumNArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
remoteName := strings.Split(cmd.Parent().Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
Expand Down Expand Up @@ -114,7 +114,6 @@ var cmdDeploymentResetUsers = &cobra.Command{
Long: `Removes all users credentials on your remote. All users will
no longer be able to log in and view or configure the deployment
from the web app.`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
remoteName := strings.Split(cmd.Parent().Parent().Use, " ")[0]
deployment, _, err := local.GetClient(remoteName, configFilePath, cmd)
Expand Down

0 comments on commit 696e3ff

Please sign in to comment.