-
Notifications
You must be signed in to change notification settings - Fork 18
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
8 changed files
with
444 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,110 @@ | ||
package main | ||
|
||
// initCmd represents the init command | ||
import ( | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/ubclaunchpad/inertia/client" | ||
"github.com/ubclaunchpad/inertia/common" | ||
"github.com/ubclaunchpad/inertia/local" | ||
"github.com/ubclaunchpad/inertia/provision" | ||
) | ||
|
||
// Initialize "inertia" commands regarding basic configuration | ||
func init() { | ||
cmdProvisionECS.Flags().StringP( | ||
"type", "t", "m3.medium", "The ec2 instance type to instantiate", | ||
) | ||
cmdProvisionECS.Flags().Bool( | ||
"from-env", false, "Load ec2 credentials from environment - requires AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY to be set.", | ||
) | ||
cmdProvision.AddCommand(cmdProvisionECS) | ||
cmdRoot.AddCommand(cmdProvision) | ||
} | ||
|
||
var cmdProvision = &cobra.Command{ | ||
Use: "provision", | ||
Short: "[BETA] Provision a new VPS setup for Inertia", | ||
Long: `[BETA] Provision a new VPS instance set up for continuous deployment with Inertia.`, | ||
} | ||
|
||
var cmdProvisionECS = &cobra.Command{ | ||
Use: "ec2 [name]", | ||
Short: "[BETA] Provision a new Amazon EC2 instance", | ||
Long: `[BETA] Provision a new Amazon EC2 instance and set it up for continuous deployment | ||
with Inertia.`, | ||
Args: cobra.MinimumNArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
// Ensure project initialized. | ||
config, path, err := local.GetProjectConfigFromDisk() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Load flags | ||
fromEnv, _ := cmd.Flags().GetBool("from-env") | ||
instanceType, _ := cmd.Flags().GetString("type") | ||
|
||
// Create VPS instance | ||
var prov *provision.EC2Provisioner | ||
if !fromEnv { | ||
id, key, err := enterEC2CredentialsWalkthrough(os.Stdin) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
prov = provision.NewEC2Provisioner(id, key) | ||
} else { | ||
prov = provision.NewEC2ProvisionerFromEnv() | ||
} | ||
|
||
// List regions and prompt for input | ||
regions, err := prov.ListRegions() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
region, err := chooseFromListWalkthrough(os.Stdin, "region", regions) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// List image options and prompt for input | ||
images, err := prov.ListImageOptions(region) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
image, err := chooseFromListWalkthrough(os.Stdin, "image", images) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Create instance from input | ||
remote, err := prov.CreateInstance(args[0], image, instanceType, region) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// Save new remote to configuration | ||
remote.Branch, err = local.GetRepoCurrentBranch() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
config.AddRemote(remote) | ||
config.Write(path) | ||
|
||
// Init the new instance | ||
inertia, found := client.NewClient(args[0], config) | ||
if !found { | ||
log.Fatal("vps setup did not complete properly") | ||
} | ||
gitURL, err := local.GetRepoRemote("origin") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
err = inertia.BootstrapRemote(common.ExtractRepository(gitURL)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} |
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,2 @@ | ||
// Package provision contains Inertia's VPS instance provisioning API | ||
package provision |
Oops, something went wrong.