Skip to content

Commit

Permalink
template wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nzoschke committed Oct 12, 2015
1 parent 89c5138 commit 435744a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 16 deletions.
1 change: 1 addition & 0 deletions api/bin/web
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions api/models/manifest.go
Expand Up @@ -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
}
Expand Down
59 changes: 50 additions & 9 deletions api/models/ssl.go
Expand Up @@ -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"
)
Expand All @@ -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
Expand All @@ -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
Expand Down
23 changes: 23 additions & 0 deletions api/models/templates/app.tmpl
Expand Up @@ -8,6 +8,7 @@
"Parameters" : {
{{ template "balancer-params" . }}
{{ template "process-params" . }}
{{ template "ssl-params" . }}

"Cluster": {
"Type" : "String",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 435744a

Please sign in to comment.