From 5ea41923c708946185556b443dde1ddb4ef3145a Mon Sep 17 00:00:00 2001 From: Lee Brown Date: Tue, 13 Aug 2019 18:12:20 -0800 Subject: [PATCH] fix deploy script --- cmd/web-api/ecs-task-definition.json | 2 +- cmd/web-app/ecs-task-definition.json | 2 +- internal/platform/devops/ecs_service.go | 13 +++++++++++++ tools/devops/README.md | 9 ++++++++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cmd/web-api/ecs-task-definition.json b/cmd/web-api/ecs-task-definition.json index 036b2e6..e4fa7a2 100644 --- a/cmd/web-api/ecs-task-definition.json +++ b/cmd/web-api/ecs-task-definition.json @@ -14,7 +14,7 @@ "awslogs-group": "{AWS_LOGS_GROUP}", "awslogs-region": "{AWS_REGION}", "awslogs-stream-prefix": "ecs", - "awslogs-datetime-format": "%Y-%m-%d %H:%M:%S.%f" + "awslogs-datetime-format": "%Y/%m/%d %H:%M:%S.%L" } }, "portMappings": [ diff --git a/cmd/web-app/ecs-task-definition.json b/cmd/web-app/ecs-task-definition.json index 639ba67..e4adfab 100644 --- a/cmd/web-app/ecs-task-definition.json +++ b/cmd/web-app/ecs-task-definition.json @@ -14,7 +14,7 @@ "awslogs-group": "{AWS_LOGS_GROUP}", "awslogs-region": "{AWS_REGION}", "awslogs-stream-prefix": "ecs", - "awslogs-datetime-format": "%Y-%m-%d %H:%M:%S.%f" + "awslogs-datetime-format": "%Y/%m/%d %H:%M:%S.%L" } }, "portMappings": [ diff --git a/internal/platform/devops/ecs_service.go b/internal/platform/devops/ecs_service.go index eb04f92..5cdc5c7 100644 --- a/internal/platform/devops/ecs_service.go +++ b/internal/platform/devops/ecs_service.go @@ -96,6 +96,10 @@ func RegisterEcsServiceTasksRoute53(log *log.Logger, awsSession *session.Session return errors.Wrapf(err, "failed to list tasks for cluster '%s' service '%s'", ecsClusterName, ecsServiceName) } + if len(servceTaskRes.TaskArns) == 0 { + continue + } + taskRes, err := svc.DescribeTasks(&ecs.DescribeTasksInput{ Cluster: aws.String(ecsClusterName), Tasks: servceTaskRes.TaskArns, @@ -148,6 +152,10 @@ func RegisterEcsServiceTasksRoute53(log *log.Logger, awsSession *session.Session time.Sleep((time.Duration(a) * time.Second * 10) * time.Duration(a)) } + if len(networkInterfaceIds) == 0 { + return errors.New("Unable to update public IPs. No network interfaces found.") + } + log.Println("Get public IPs for network interface IDs.") var publicIps []string for a := 0; a <= 3; a++ { @@ -202,7 +210,11 @@ func RegisterEcsServiceTasksRoute53(log *log.Logger, awsSession *session.Session } // Add all the A record names with the same set of public IPs. + addedNames := make(map[string]bool) for _, aName := range aNames { + if addedNames[aName] { + continue + } log.Printf("\t\tAdd A record for '%s'.\n", aName) input.ChangeBatch.Changes = append(input.ChangeBatch.Changes, &route53.Change{ @@ -214,6 +226,7 @@ func RegisterEcsServiceTasksRoute53(log *log.Logger, awsSession *session.Session Type: aws.String("A"), }, }) + addedNames[aName] = true } _, err := svc.ChangeResourceRecordSets(input) diff --git a/tools/devops/README.md b/tools/devops/README.md index 7e93bb7..1b1f8e2 100644 --- a/tools/devops/README.md +++ b/tools/devops/README.md @@ -234,4 +234,11 @@ instance will be a dedicated host since we need it always up and running, thus i Once complete, restart the runner. ```bash sudo gitlab-runner restart - ``` \ No newline at end of file + ``` + + +## Examples + +```bash +go run main.go deploy -service=web-app -env=dev -enable_https=true -primary_host=example.saasstartupkit.com -host_names=example.saasstartupkit.com,dev.example.saasstartupkit.com -private_bucket=saas-starter-kit-private -public_bucket=saas-starter-kit-public -public_bucket_cloudfront=true -static_files_s3=true -static_files_img_resize=1 -recreate_service=0 +``` \ No newline at end of file