Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PACKAGES = $(shell go list ./... | grep -v '/vendor/')
format:
@echo "--> Running go fmt"
@go fmt $(PACKAGES)
18 changes: 18 additions & 0 deletions command/amazon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package command

import (
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/s3"
)

type AmazonServices struct {
Iam *iam.IAM
Ec2 *ec2.EC2
Elb *elb.ELB
Asg *autoscaling.AutoScaling
S3 *s3.S3
S3Keys *s3.S3
}
10 changes: 5 additions & 5 deletions command/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/hello/sanders/ui"
"sort"
"strconv"
"strings"
"time"
"strconv"
"sort"
)

const plan = `
Expand Down Expand Up @@ -202,12 +202,12 @@ func (c *CanaryCommand) update(service *autoscaling.AutoScaling, desiredCapacity
return resp, err
}

func (c *CanaryCommand) updateASGTag(service *autoscaling.AutoScaling, asgName string, tagName string, tagValue string, propagate bool) (*autoscaling.CreateOrUpdateTagsOutput, error){
func (c *CanaryCommand) updateASGTag(service *autoscaling.AutoScaling, asgName string, tagName string, tagValue string, propagate bool) (*autoscaling.CreateOrUpdateTagsOutput, error) {

//Tag the ASG so version number can be passed to instance
params := &autoscaling.CreateOrUpdateTagsInput{
Tags: []*autoscaling.Tag{// Required
{// Required
Tags: []*autoscaling.Tag{ // Required
{ // Required
Key: aws.String(tagName), // Required
PropagateAtLaunch: aws.Bool(propagate),
ResourceId: aws.String(asgName),
Expand Down
12 changes: 3 additions & 9 deletions command/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/mitchellh/cli"
"sort"
Expand All @@ -13,6 +12,7 @@ import (
type CleanCommand struct {
Ui cli.ColoredUi
Notifier BasicNotifier
Services *AmazonServices
}

func (c *CleanCommand) Help() string {
Expand All @@ -22,20 +22,14 @@ func (c *CleanCommand) Help() string {

func (c *CleanCommand) Run(args []string) int {

config := &aws.Config{
Region: aws.String("us-east-1"),
}

asgService := autoscaling.New(session.New(), config)

lcParams := &autoscaling.DescribeLaunchConfigurationsInput{
MaxRecords: aws.Int64(100),
}

pageNum := 0
allLcs := make([]*autoscaling.LaunchConfiguration, 0)

pageErr := asgService.DescribeLaunchConfigurationsPages(lcParams, func(page *autoscaling.DescribeLaunchConfigurationsOutput, lastPage bool) bool {
pageErr := c.Services.Asg.DescribeLaunchConfigurationsPages(lcParams, func(page *autoscaling.DescribeLaunchConfigurationsOutput, lastPage bool) bool {
pageNum++
if len(page.LaunchConfigurations) == 0 {
return false
Expand Down Expand Up @@ -80,7 +74,7 @@ func (c *CleanCommand) Run(args []string) int {
params := &autoscaling.DeleteLaunchConfigurationInput{
LaunchConfigurationName: lcName,
}
_, err := asgService.DeleteLaunchConfiguration(params)
_, err := c.Services.Asg.DeleteLaunchConfiguration(params)

if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
Expand Down
45 changes: 22 additions & 23 deletions command/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ package command

import (
"bytes"
"encoding/base64"
"crypto/sha1"
"io"
"encoding/base64"
"flag"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/mitchellh/cli"
"io"
"sort"
"strconv"
"strings"
"time"
"flag"
)

type suripuApp struct {
Expand All @@ -28,7 +28,7 @@ type suripuApp struct {
targetDesiredCapacity int64 //This is the desired capacity of the asg targeted for deployment
usesPacker bool
javaVersion int
packagePath string
packagePath string
}

//This hash should be updated anytime default_userdata.sh is updated on S3
Expand All @@ -43,7 +43,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 2,
usesPacker: false,
javaVersion: 7,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "suripu-service",
sg: "sg-11ac0e75",
Expand All @@ -52,7 +52,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 4,
usesPacker: false,
javaVersion: 7,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "suripu-workers",
sg: "sg-7054d714",
Expand All @@ -61,7 +61,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 2,
usesPacker: false,
javaVersion: 7,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "suripu-admin",
sg: "sg-71773a16",
Expand All @@ -70,7 +70,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 1,
usesPacker: false,
javaVersion: 7,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "logsindexer",
sg: "sg-36f95050",
Expand All @@ -79,7 +79,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 1,
usesPacker: false,
javaVersion: 8,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "sense-firehose",
sg: "sg-5296b834",
Expand All @@ -88,7 +88,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 1,
usesPacker: false,
javaVersion: 8,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "hello-time",
sg: "sg-5c371525",
Expand All @@ -97,7 +97,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 2,
usesPacker: false,
javaVersion: 7,
packagePath: "com/hello/time"},
packagePath: "com/hello/time"},
suripuApp{
name: "suripu-queue",
sg: "sg-3e55ba46",
Expand All @@ -106,7 +106,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 1,
usesPacker: false,
javaVersion: 7,
packagePath: "com/hello/suripu"},
packagePath: "com/hello/suripu"},
suripuApp{
name: "messeji",
sg: "sg-45c5c73c",
Expand All @@ -115,7 +115,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 4,
usesPacker: false,
javaVersion: 8,
packagePath: "com/hello"},
packagePath: "com/hello"},
suripuApp{
name: "taimurain",
sg: "sg-b3f631c8",
Expand All @@ -124,7 +124,7 @@ var suripuApps []suripuApp = []suripuApp{
targetDesiredCapacity: 3,
usesPacker: true,
javaVersion: 8,
packagePath: "com/hello"},
packagePath: "com/hello"},
}

var keyBucket string = "hello-keys"
Expand Down Expand Up @@ -298,7 +298,6 @@ func (c *CreateCommand) Run(args []string) int {
amiVersion = amiNameInfo[1]
}


} else {

canaryPath := ""
Expand Down Expand Up @@ -427,9 +426,9 @@ func (c *CreateCommand) Run(args []string) int {
key := fmt.Sprintf("/%s/%s/%s.pem", environment, selectedApp.name, *keyPairResp.KeyName)

uploadResult, err := s3KeyService.PutObject(&s3.PutObjectInput{
Body: strings.NewReader(*keyPairResp.KeyMaterial),
Bucket: aws.String(keyBucket),
Key: &key,
Body: strings.NewReader(*keyPairResp.KeyMaterial),
Bucket: aws.String(keyBucket),
Key: &key,
})

if err != nil {
Expand All @@ -447,8 +446,8 @@ func (c *CreateCommand) Run(args []string) int {
InstanceMonitoring: &autoscaling.InstanceMonitoring{
Enabled: aws.Bool(true),
},
InstanceType: aws.String(selectedApp.instanceType),
KeyName: aws.String(keyName),
InstanceType: aws.String(selectedApp.instanceType),
KeyName: aws.String(keyName),
SecurityGroups: []*string{
aws.String(selectedApp.sg), // Required
},
Expand Down Expand Up @@ -490,7 +489,7 @@ func (c *CreateCommand) Run(args []string) int {
return 0
}

func Cleanup(keyName string, objectName string, ui cli.ColoredUi ) bool {
func Cleanup(keyName string, objectName string, ui cli.ColoredUi) bool {

ui.Info("")
ui.Info(fmt.Sprintf("Cleaning up created KeyPair: %s", keyName))
Expand All @@ -515,8 +514,8 @@ func Cleanup(keyName string, objectName string, ui cli.ColoredUi ) bool {

//Delete pem file from s3
delParams := &s3.DeleteObjectInput{
Bucket: aws.String(keyBucket), // Required
Key: aws.String(objectName), // Required
Bucket: aws.String(keyBucket), // Required
Key: aws.String(objectName), // Required
}
_, objErr := s3KeyService.DeleteObject(delParams)

Expand Down
10 changes: 5 additions & 5 deletions command/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func (c *HostsCommand) Run(args []string) int {

groupnames := make([]*string, 0)
for _, app := range suripuApps {
one := fmt.Sprintf("%s-prod", app.name)
two := fmt.Sprintf("%s-prod-green", app.name)
groupnames = append(groupnames, &one)
groupnames = append(groupnames, &two)
}
one := fmt.Sprintf("%s-prod", app.name)
two := fmt.Sprintf("%s-prod-green", app.name)
groupnames = append(groupnames, &one)
groupnames = append(groupnames, &two)
}

req := &autoscaling.DescribeAutoScalingGroupsInput{
AutoScalingGroupNames: groupnames,
Expand Down
31 changes: 15 additions & 16 deletions command/monitor.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package command

import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/mitchellh/cli"
"strings"
"strconv"
"time"
"github.com/mitchellh/cli"
"strconv"
"strings"
"time"
)

type MonitorCommand struct {
Expand All @@ -28,7 +28,7 @@ func (c *MonitorCommand) Run(args []string) int {
Region: aws.String("us-east-1"),
}

elbs := []string{
elbs := []string{
"suripu-service-prod",
"suripu-app-prod",
"suripu-app-canary",
Expand All @@ -41,7 +41,7 @@ func (c *MonitorCommand) Run(args []string) int {
service := elb.New(session.New(), config)
ec2Service := ec2.New(session.New(), config)

for idx, elb := range elbs {
for idx, elb := range elbs {
c.Ui.Output(fmt.Sprintf("[%d] %s", idx, elb))
}

Expand All @@ -55,17 +55,16 @@ func (c *MonitorCommand) Run(args []string) int {

selectedElb := elbs[elbIdx]

for {
status := elbStatus(selectedElb, service, ec2Service)
printStatus(c.Ui, status)
c.Ui.Output("\nSleeping for 10 seconds...\n")
time.Sleep(10000 * time.Millisecond)
}
for {
status := elbStatus(selectedElb, service, ec2Service)
printStatus(c.Ui, status)
c.Ui.Output("\nSleeping for 10 seconds...\n")
time.Sleep(10000 * time.Millisecond)
}

return 0
return 0
}


func (c *MonitorCommand) Synopsis() string {
return "Monitor ELB status"
}
Loading