This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
installer,cli,dashboard: Add installer web app
Makes `flynn install` run web app interface for installer and removes all other options. The install cert view is shared between the installer and dashboard. Signed-off-by: Jesse Stuart <jesse@jessestuart.ca>
- Loading branch information
Showing
65 changed files
with
22,032 additions
and
323 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,135 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"strconv" | ||
|
||
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws" | ||
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt" | ||
"github.com/flynn/flynn/installer" | ||
) | ||
|
||
func init() { | ||
register("install", runInstaller, fmt.Sprintf(` | ||
usage: flynn install <target> [-n <instances>] [-t <instance-type>] [--aws-access-key-id=<key-id>] [--aws-secret-access-key=<secret>] [--aws-region=<region>] [--vpc-cidr=<cidr>] [--subnet-cidr=<cidr>] | ||
usage: flynn install | ||
Targets: | ||
aws creates a flynn cluster on EC2 | ||
Options: | ||
-n <instances>, --instances=<instances> Number of instances to launch [default: 1] | ||
-t <instance-type>, --type=<instance-type> Type of instances to launch [default: %s] | ||
--aws-access-key-id=<key-id> AWS access key ID. Defaults to $AWS_ACCESS_KEY_ID | ||
--aws-secret-access-key=<secret> AWS access key secret. Defaults to $AWS_SECRET_ACCESS_KEY | ||
--aws-region=<region> AWS region [default: us-east-1] | ||
--vpc-cidr=<cidr> CIDR block to assign to the VPC. [default: 10.0.0.0/16] | ||
--subnet-cidr=<cidr> CIDR block to assign to the subnet. [default: 10.0.0.0/21] | ||
Starts server for installer web interface. | ||
Examples: | ||
$ flynn install aws --aws-access-key-id=asdf --aws-secret-access-key=fdsa | ||
$ flynn install | ||
`, installer.DefaultInstanceType)) | ||
} | ||
|
||
func runInstaller(args *docopt.Args) error { | ||
if args.String["<target>"] != "aws" { | ||
return errors.New("Invalid install target") | ||
} | ||
var creds aws.CredentialsProvider | ||
key := args.String["--aws-access-key-id"] | ||
secret := args.String["--aws-secret-access-key"] | ||
if key != "" && secret != "" { | ||
creds = aws.Creds(key, secret, "") | ||
} else { | ||
var err error | ||
creds, err = aws.EnvCreds() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
instanceType := args.String["--type"] | ||
|
||
region := args.String["--aws-region"] | ||
if region == "" { | ||
region = "us-east-1" | ||
} | ||
|
||
instances := 1 | ||
if args.String["--instances"] != "" { | ||
var err error | ||
instances, err = strconv.Atoi(args.String["--instances"]) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
vpcCidr := args.String["--vpc-cidr"] | ||
if vpcCidr == "" { | ||
vpcCidr = "10.0.0.0/21" | ||
} | ||
|
||
subnetCidr := args.String["--subnet-cidr"] | ||
if subnetCidr == "" { | ||
subnetCidr = "10.0.0.0/21" | ||
} | ||
|
||
stack := &installer.Stack{ | ||
NumInstances: instances, | ||
InstanceType: instanceType, | ||
Region: region, | ||
VpcCidr: vpcCidr, | ||
SubnetCidr: subnetCidr, | ||
Creds: creds, | ||
YesNoPrompt: promptYesNo, | ||
PromptInput: promptInput, | ||
} | ||
if err := stack.RunAWS(); err != nil { | ||
return err | ||
} | ||
|
||
exitCode := 0 | ||
outer: | ||
for { | ||
select { | ||
case event := <-stack.EventChan: | ||
fmt.Println(event.Description) | ||
case err := <-stack.ErrChan: | ||
fmt.Printf("Oops, something went wrong: %s\n", err.Error()) | ||
exitCode = 1 | ||
case <-stack.Done: | ||
if exitCode != 0 { | ||
os.Exit(exitCode) | ||
} | ||
break outer | ||
} | ||
} | ||
|
||
if err := readConfig(); err != nil { | ||
return err | ||
} | ||
if err := config.Add(stack.ClusterConfig(), true); err != nil { | ||
return err | ||
} | ||
config.SetDefault(stack.StackName) | ||
if err := config.SaveTo(configPath()); err != nil { | ||
return err | ||
} | ||
|
||
msg, _ := stack.DashboardLoginMsg() | ||
fmt.Printf("\n\nThe cluster has been successfully deployed to AWS and configured locally.\n\n%s\n\n", msg) | ||
|
||
return nil | ||
} | ||
|
||
func promptInput(msg string) (result string) { | ||
fmt.Print(msg) | ||
fmt.Print(": ") | ||
for { | ||
var answer string | ||
fmt.Scanln(&answer) | ||
return answer | ||
} | ||
return installer.ServeHTTP() | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build | ||
.sass-cache | ||
dashboard.tar | ||
lib/installer |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
include_rules | ||
|
||
: $(ROOT)/util/cedarish/<docker> |> ^ docker build dashboard-builder^ cat $(ROOT)/log/docker-cedarish.log > /dev/null && ./build.sh image | tee %o |> $(ROOT)/log/docker-dashboard-builder.log <docker> | ||
: $(ROOT)/log/docker-dashboard-builder.log |> ./build.sh app |> dashboard.tar | ||
: foreach $(ROOT)/installer/app/src/images/*.png |> !cp |> ./lib/installer/images/%g.png | ||
: foreach $(ROOT)/installer/app/src/views/*.js.jsx |> !cp |> ./lib/installer/views/%g.js.jsx | ||
: foreach $(ROOT)/installer/app/src/views/css/*.js |> !cp |> ./lib/installer/views/css/%g.js | ||
: ./lib/installer/images/* ./lib/installer/views/* ./lib/installer/views/css/* $(ROOT)/log/docker-dashboard-builder.log |> ./build.sh app |> dashboard.tar |
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,25 @@ | ||
module Dashboard | ||
module InstallerImport | ||
BASE_PATH = ENV['INSTALLER_SRC_DIR'] || File.expand_path('../../installer', __FILE__) | ||
|
||
extend self | ||
|
||
def javascript(path) | ||
if path[0] != '/' | ||
path = File.join(BASE_PATH, path) | ||
end | ||
unless File.exists?(path) | ||
if ext = %w[ .js .js.jsx ].find { |i| File.exists?(path + i) } | ||
path = path + ext | ||
else | ||
throw "Asset not found: #{path}" | ||
end | ||
end | ||
data = File.read(path) | ||
|
||
data.gsub!(/^(?:import|export) .*$/, '') | ||
|
||
data | ||
end | ||
end | ||
end |
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.