From 435744ae95ace3252b92dddce7f7b3378348aeec Mon Sep 17 00:00:00 2001 From: Noah Zoschke Date: Mon, 12 Oct 2015 13:40:15 -0700 Subject: [PATCH] template wip --- api/bin/web | 1 + api/models/manifest.go | 15 ++++----- api/models/ssl.go | 59 +++++++++++++++++++++++++++++------ api/models/templates/app.tmpl | 23 ++++++++++++++ 4 files changed, 82 insertions(+), 16 deletions(-) diff --git a/api/bin/web b/api/bin/web index 91f7daedf2..f8abf13019 100755 --- a/api/bin/web +++ b/api/bin/web @@ -5,6 +5,7 @@ haproxy -f /etc/haproxy/haproxy.cfg & if [ "$DEVELOPMENT" == "true" ]; then + go get -u github.com/jteeuwen/go-bindata/... $GOPATH/bin/rerun -build github.com/convox/rack/api else $GOPATH/bin/api diff --git a/api/models/manifest.go b/api/models/manifest.go index c15fceb065..f238d93ead 100644 --- a/api/models/manifest.go +++ b/api/models/manifest.go @@ -17,13 +17,14 @@ type Manifest []ManifestEntry type ManifestEntry struct { Name string - Build string `yaml:"build"` - Command interface{} `yaml:"command"` - Env []string `yaml:"environment"` - Image string `yaml:"image"` - Links []string `yaml:"links"` - Ports []string `yaml:"ports"` - Volumes []string `yaml:"volumes"` + Build string `yaml:"build"` + Command interface{} `yaml:"command"` + Env []string `yaml:"environment"` + Image string `yaml:"image"` + Links []string `yaml:"links"` + Ports []string `yaml:"ports"` + SSLPorts []string `yaml:"ssl_ports"` + Volumes []string `yaml:"volumes"` randoms map[string]int } diff --git a/api/models/ssl.go b/api/models/ssl.go index 8f1d858089..2d1ff719d6 100644 --- a/api/models/ssl.go +++ b/api/models/ssl.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/elb" "github.com/aws/aws-sdk-go/service/iam" ) @@ -24,13 +25,11 @@ func CreateSSL(a, port, body, key string) (*SSL, error) { return nil, err } - params := &iam.UploadServerCertificateInput{ + resp, err := IAM().UploadServerCertificate(&iam.UploadServerCertificateInput{ CertificateBody: aws.String(body), PrivateKey: aws.String(key), ServerCertificateName: aws.String(fmt.Sprintf("%s", a)), - } - - resp, err := IAM().UploadServerCertificate(params) + }) if err != nil { return nil, err @@ -45,12 +44,54 @@ func CreateSSL(a, port, body, key string) (*SSL, error) { Arn: *arn, } - fmt.Println("%+v\n", app) - stack_params := map[string]string{} - stack_params[fmt.Sprintf("SSL%sArn", port)] = ssl.Arn - stack_params[fmt.Sprintf("SSL%sPort", port)] = ssl.Port + release, err := app.LatestRelease() + + if err != nil { + return nil, err + } + + manifest, err := LoadManifest(release.Manifest) + + if err != nil { + return nil, err + } + + // TODO: find correct entry based on internal port + manifest[0].SSLPorts = []string{fmt.Sprintf("%s:3000", port)} + + template, err := manifest.Formation() + + if err != nil { + return nil, err + } + + fmt.Printf("%s\n", template) + + // WebPort443Balancer 443 + // WebPort443Host 30753 + // WebPort443ARN iam::... + + req := &cloudformation.UpdateStackInput{ + StackName: aws.String(app.Name), + Capabilities: []*string{aws.String("CAPABILITY_IAM")}, + } + + params := app.Parameters + + params[fmt.Sprintf("WebSSL%sArn", port)] = ssl.Arn + params[fmt.Sprintf("WebSSL%sBalancer", port)] = ssl.Port + params[fmt.Sprintf("WebSSL%sHost", port)] = "3000" + + for key, val := range params { + req.Parameters = append(req.Parameters, &cloudformation.Parameter{ + ParameterKey: aws.String(key), + ParameterValue: aws.String(val), + }) + } + + req.TemplateBody = aws.String(template) - err = app.UpdateParams(stack_params) + _, err = CloudFormation().UpdateStack(req) if err != nil { return nil, err diff --git a/api/models/templates/app.tmpl b/api/models/templates/app.tmpl index 602e1d86e2..57f33ae4a9 100644 --- a/api/models/templates/app.tmpl +++ b/api/models/templates/app.tmpl @@ -8,6 +8,7 @@ "Parameters" : { {{ template "balancer-params" . }} {{ template "process-params" . }} + {{ template "ssl-params" . }} "Cluster": { "Type" : "String", @@ -254,6 +255,28 @@ {{ end }} {{ end }} +{{ define "ssl-params" }} + {{ range $entry := . }} + {{ range $i, $port := $entry.SSLPorts }} + {{ $parts := (split $port ":") }} + "{{ upper $entry.Name }}SSL{{ index $parts 0 }}Balancer": { + "Type" : "String", + "Default" : "{{ index $parts 0 }}", + "Description" : "" + }, + "{{ upper $entry.Name }}SSL{{ index $parts 0 }}Host": { + "Type" : "String", + "Default" : "{{ index $entry.Randoms $port }}", + "Description" : "" + }, + "{{ upper $entry.Name }}SSL{{ index $parts 0 }}Arn": { + "Type" : "String", + "Description" : "" + }, + {{ end }} + {{ end }} +{{ end }} + {{ define "balancer-outputs" }} {{ if .HasExternalPorts }} "BalancerHost": {