Skip to content

Commit

Permalink
pull from docker image instead of ssm parameter so everyone can use it
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispruitt committed Jan 18, 2019
1 parent 8338679 commit a1e63a6
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/fatih/color"
"log"
"os"
Expand All @@ -26,7 +25,7 @@ func main() {
flag.Parse()

if *versionPtr {
fmt.Println("v1.0.0")
fmt.Println("v1.2.0")
os.Exit(0)
}

Expand All @@ -50,7 +49,7 @@ func main() {
func printDiff(x map[string]string, y map[string]string) {
emptyStr := ""

allKeys := append(getMapKeys(x), getMapKeys(y)...)
allKeys := removeDuplicates(append(getMapKeys(x), getMapKeys(y)...))
sort.Strings(allKeys)

for _, key := range allKeys {
Expand Down Expand Up @@ -88,14 +87,6 @@ func check(err error) {
}
}

func parseServiceArnList(service_arn_list []*string) []string {
var result []string
for _, ptrs := range service_arn_list {
result = append(result, strings.Split(*ptrs, "/")[1])
}
return result
}

func getMapKeys(x map[string]string) []string {
i := 0
keys := make([]string, len(x))
Expand All @@ -121,7 +112,6 @@ func getServiceVersions(cluster string, profile string) map[string]string {
sess := session.Must(session.NewSessionWithOptions(sessOpts))

svcECS := ecs.New(sess)
svcSSM := ssm.New(sess)

input := &ecs.ListServicesInput{
Cluster: aws.String(cluster),
Expand All @@ -130,18 +120,39 @@ func getServiceVersions(cluster string, profile string) map[string]string {
result, err := svcECS.ListServices(input)
check(err)

services := parseServiceArnList(result.ServiceArns)
sort.Strings(services)

for _, service := range services {
ssmOpts := ssm.GetParameterInput{
Name: aws.String(fmt.Sprintf("/%s/%s/VERSION", cluster, service)),
for _, service := range result.ServiceArns {
serviceOpts := ecs.DescribeServicesInput{
Cluster: aws.String(fmt.Sprintf(cluster)),
Services: aws.StringSlice([]string{*service}),
}
ssmResponse, err := svcSSM.GetParameter(&ssmOpts)
serviceResponse, err := svcECS.DescribeServices(&serviceOpts)
check(err)

resultMap[service] = *ssmResponse.Parameter.Value
serviceName := *serviceResponse.Services[0].ServiceName

taskDefOpts := ecs.DescribeTaskDefinitionInput{
TaskDefinition: aws.String(*serviceResponse.Services[0].TaskDefinition),
}

taskResponse, err := svcECS.DescribeTaskDefinition(&taskDefOpts)

dockerImage := *taskResponse.TaskDefinition.ContainerDefinitions[0].Image

resultMap[serviceName] = strings.Split(dockerImage, ":")[1]

}

return resultMap
}

func removeDuplicates(stringSlice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range stringSlice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}

0 comments on commit a1e63a6

Please sign in to comment.