From c64a263fa5151301dbff92e244e9566fd5043e7c Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 17:33:41 -0700 Subject: [PATCH 01/18] adds bash for querying the status of a deployment --- src/orb.yml.hbs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 3eed55d7..ad762528 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -973,6 +973,26 @@ commands: --revision "{\"revisionType\": \"AppSpecContent\", \"appSpecContent\": {\"content\": \"{\\\"version\\\": 1, \\\"Resources\\\": [{\\\"TargetService\\\": {\\\"Type\\\": \\\"AWS::ECS::Service\\\", \\\"Properties\\\": {\\\"TaskDefinition\\\": \\\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\\\", \\\"LoadBalancerInfo\\\": {\\\"ContainerName\\\": \\\"<< parameters.codedeploy-load-balanced-container-name >>\\\", \\\"ContainerPort\\\": << parameters.codedeploy-load-balanced-container-port >>}}}}]}\"}}" \ --query deploymentId) echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" + if [ "<< parameters.verify-revision-is-deployed >>" == "true" ]; then + seconds=3600+$SECONDS + while (( $SECONDS < $seconds )); do + DEPLOYMENT_STATUS=$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID) + echo $DEPLOYMENT_STATUS + if grep "\"status\": \"Succeeded\"" <<< $DEPLOYMENT_STATUS; then + echo "Deployment Success" + exit 0 + elif grep "\"status\": \"Failed\"" <<< $DEPLOYMENT_STATUS; then + echo "Deployment Failed" + exit 1 + elif grep "\"status\": \"Stopped\"" <<< $DEPLOYMENT_STATUS; then + echo "Deployment Stopped" + exit 1 + else + echo "Sleeping for 1 minute before retrying the status of the deployment" + sleep 60s + fi + done + fi else SERVICE_NAME="$(echo << parameters.service-name >>)" From e2cd3732ba8dde61a3e735f05979ee3ec9446ffc Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 17:36:33 -0700 Subject: [PATCH 02/18] remove readme comment on blue/green not supported for verifying revision --- src/orb.yml.hbs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index ad762528..620405bd 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -273,7 +273,6 @@ jobs: for the service. Note: enabling this may result in the build being marked as failed if tasks for older revisions fail to be stopped before the max number of polling attempts is reached. - Does not support ECS services that are of the Blue/Green Deployment type. type: boolean default: false max-poll-attempts: @@ -588,7 +587,6 @@ commands: Polls the service's deployment status at intervals until the given task definition revision is the only one deployed for the service, and for the task definition revision's running task count to match the desired count. - Does not support ECS services that are of the Blue/Green Deployment type. parameters: family: description: @@ -913,7 +911,6 @@ commands: for the service. Note: enabling this may result in the build being marked as failed if tasks for older revisions fail to be stopped before the max number of polling attempts is reached. - Does not support ECS services that are of the Blue/Green Deployment type. type: boolean default: false max-poll-attempts: From e400f16698b66fae84aa4492025efded27167c88 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 17:37:15 -0700 Subject: [PATCH 03/18] Removes unnecessary echo --- src/orb.yml.hbs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 620405bd..91e4b119 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -974,7 +974,6 @@ commands: seconds=3600+$SECONDS while (( $SECONDS < $seconds )); do DEPLOYMENT_STATUS=$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID) - echo $DEPLOYMENT_STATUS if grep "\"status\": \"Succeeded\"" <<< $DEPLOYMENT_STATUS; then echo "Deployment Success" exit 0 From 456adf1c1a74b43ec487085802cf6bdfc4caf3a9 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 17:42:07 -0700 Subject: [PATCH 04/18] Add logical branch for successful deploy if skipped --- src/orb.yml.hbs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 91e4b119..302f9856 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -983,6 +983,9 @@ commands: elif grep "\"status\": \"Stopped\"" <<< $DEPLOYMENT_STATUS; then echo "Deployment Stopped" exit 1 + elif grep "\"status\": \"Skipped\"" <<< $DEPLOYMENT_STATUS; then + echo "Deployment Skipped" + exit 0 else echo "Sleeping for 1 minute before retrying the status of the deployment" sleep 60s From a61184f4e3fc5f9aaf5cf08ba6978f0e8c8e1052 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 17:43:45 -0700 Subject: [PATCH 05/18] Failed on a skipped deploy --- src/orb.yml.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 302f9856..c2fe89d1 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -985,7 +985,7 @@ commands: exit 1 elif grep "\"status\": \"Skipped\"" <<< $DEPLOYMENT_STATUS; then echo "Deployment Skipped" - exit 0 + exit 1 else echo "Sleeping for 1 minute before retrying the status of the deployment" sleep 60s From beb8a360165c65b1eee8b6ab569398a0e3137e77 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 17:50:38 -0700 Subject: [PATCH 06/18] Add a fall through exit if code deploy never responds with a condition that exits --- src/orb.yml.hbs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index c2fe89d1..43f8f94f 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -991,6 +991,8 @@ commands: sleep 60s fi done + echo "No response from Code deploy, exiting." + exit 1 fi else SERVICE_NAME="$(echo << parameters.service-name >>)" From c5bd188b165249b2762cc5132a90a48ce7c6b957 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Thu, 4 Jun 2020 20:27:24 -0700 Subject: [PATCH 07/18] Fix removal of a README item for an unrelated feature --- src/orb.yml.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 43f8f94f..87410671 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -587,6 +587,7 @@ commands: Polls the service's deployment status at intervals until the given task definition revision is the only one deployed for the service, and for the task definition revision's running task count to match the desired count. + Does not support ECS services that are of the Blue/Green Deployment type. parameters: family: description: From 3ae7acaae56bdd3617994cc0a01debd26a7dbd12 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Fri, 5 Jun 2020 07:42:19 -0700 Subject: [PATCH 08/18] Escapes <<< --- src/orb.yml.hbs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 87410671..fc6c31b5 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -975,16 +975,16 @@ commands: seconds=3600+$SECONDS while (( $SECONDS < $seconds )); do DEPLOYMENT_STATUS=$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID) - if grep "\"status\": \"Succeeded\"" <<< $DEPLOYMENT_STATUS; then + if grep "\"status\": \"Succeeded\"" \<<< $DEPLOYMENT_STATUS; then echo "Deployment Success" exit 0 - elif grep "\"status\": \"Failed\"" <<< $DEPLOYMENT_STATUS; then + elif grep "\"status\": \"Failed\"" \<<< $DEPLOYMENT_STATUS; then echo "Deployment Failed" exit 1 - elif grep "\"status\": \"Stopped\"" <<< $DEPLOYMENT_STATUS; then + elif grep "\"status\": \"Stopped\"" \<<< $DEPLOYMENT_STATUS; then echo "Deployment Stopped" exit 1 - elif grep "\"status\": \"Skipped\"" <<< $DEPLOYMENT_STATUS; then + elif grep "\"status\": \"Skipped\"" \<<< $DEPLOYMENT_STATUS; then echo "Deployment Skipped" exit 1 else From b476b15634a40713dd160bd8c9ba918a674b0964 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Sat, 6 Jun 2020 08:26:16 -0700 Subject: [PATCH 09/18] Simplify the sleep into using aws deploy wait, and add test case --- .circleci/config.yml | 19 ++++++++++++++++++- src/orb.yml.hbs | 28 ++++++---------------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 371f6583..645ce08f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -656,7 +656,6 @@ workflows: codedeploy-deployment-group-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-codedeploygroup" codedeploy-load-balanced-container-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" codedeploy-load-balanced-container-port: 8080 - # verify-revision-is-deployed is not supported for blue/green deployment type services verify-revision-is-deployed: false post-steps: - wait-for-codedeploy-deployment: @@ -670,6 +669,24 @@ workflows: service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" + - aws-ecs/deploy-service-update: + name: codedeploy_fargate_test-update-service-job + docker-image-for-job: circleci/python:3.4.9 + requires: + - codedeploy_fargate_test-update-service-command + aws-access-key-id: "${AWS_ACCESS_KEY_ID}" + aws-region: "${AWS_DEFAULT_REGION}" + family: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" + cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" + container-image-name-updates: "container=${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service,image-and-tag=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}:${CIRCLE_SHA1}" + container-env-var-updates: "container=${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service,name=VERSION_INFO,value=\"${CIRCLE_SHA1}_${CIRCLE_BUILD_NUM}\",container=${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service,name=BUILD_DATE,value=$(date)" + deployment-controller: "CODE_DEPLOY" + codedeploy-application-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-codedeployapp" + codedeploy-deployment-group-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-codedeploygroup" + codedeploy-load-balanced-container-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" + codedeploy-load-balanced-container-port: 8080 + verify-revision-is-deployed: true + - tear-down-test-env: name: ec2_tear-down-test-env requires: diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index fc6c31b5..dc4ea057 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -972,28 +972,12 @@ commands: --query deploymentId) echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" if [ "<< parameters.verify-revision-is-deployed >>" == "true" ]; then - seconds=3600+$SECONDS - while (( $SECONDS < $seconds )); do - DEPLOYMENT_STATUS=$(aws deploy get-deployment --deployment-id $DEPLOYMENT_ID) - if grep "\"status\": \"Succeeded\"" \<<< $DEPLOYMENT_STATUS; then - echo "Deployment Success" - exit 0 - elif grep "\"status\": \"Failed\"" \<<< $DEPLOYMENT_STATUS; then - echo "Deployment Failed" - exit 1 - elif grep "\"status\": \"Stopped\"" \<<< $DEPLOYMENT_STATUS; then - echo "Deployment Stopped" - exit 1 - elif grep "\"status\": \"Skipped\"" \<<< $DEPLOYMENT_STATUS; then - echo "Deployment Skipped" - exit 1 - else - echo "Sleeping for 1 minute before retrying the status of the deployment" - sleep 60s - fi - done - echo "No response from Code deploy, exiting." - exit 1 + echo "Waiting for deployment to succeed." + if $(aws deploy wait deployment-successful --deployment-id ${DEPLOYMENT_ID}); then + echo "Deployment succeeded." + else + echo "Deployment failed." + fi fi else SERVICE_NAME="$(echo << parameters.service-name >>)" From 38b13019fb54c86f844845c63d38a2792ae8d6bc Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Sat, 6 Jun 2020 08:32:49 -0700 Subject: [PATCH 10/18] add post steps --- .circleci/config.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 645ce08f..b0d17344 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -686,6 +686,14 @@ workflows: codedeploy-load-balanced-container-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" codedeploy-load-balanced-container-port: 8080 verify-revision-is-deployed: true + post_steps: + - test-deployment: + service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" + cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" + delete-load-balancer: true + - delete-service: + service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" + cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" - tear-down-test-env: name: ec2_tear-down-test-env From e2c19b6d6b3ceb3511423a02a72ec975ed984494 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Sat, 6 Jun 2020 08:37:39 -0700 Subject: [PATCH 11/18] update tests name and ensure test env persists until after job completes --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b0d17344..9126b181 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -670,7 +670,7 @@ workflows: cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" - aws-ecs/deploy-service-update: - name: codedeploy_fargate_test-update-service-job + name: codedeploy_fargate_test-update-and-wait-service-job docker-image-for-job: circleci/python:3.4.9 requires: - codedeploy_fargate_test-update-service-command @@ -714,6 +714,7 @@ workflows: name: codedeploy_fargate_tear-down-test-env requires: - codedeploy_fargate_test-update-service-job + - codedeploy_fargate_test-update-and-wait-service-job terraform-image: "hashicorp/terraform:0.12.16" aws-resource-name-prefix: ${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE} terraform-config-dir: "tests/terraform_setup/fargate_codedeploy" From 2d6f1b14059d4929a5d8c4d73e41c18d64cbb33a Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Sat, 13 Jun 2020 16:52:48 -0700 Subject: [PATCH 12/18] Add revisions based on pr feedback --- .circleci/config.yml | 7 +------ src/orb.yml.hbs | 5 ++++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9126b181..5eca7fd2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -673,7 +673,7 @@ workflows: name: codedeploy_fargate_test-update-and-wait-service-job docker-image-for-job: circleci/python:3.4.9 requires: - - codedeploy_fargate_test-update-service-command + - codedeploy_fargate_test-update-service-job aws-access-key-id: "${AWS_ACCESS_KEY_ID}" aws-region: "${AWS_DEFAULT_REGION}" family: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" @@ -691,10 +691,6 @@ workflows: service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" delete-load-balancer: true - - delete-service: - service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" - cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" - - tear-down-test-env: name: ec2_tear-down-test-env requires: @@ -713,7 +709,6 @@ workflows: - tear-down-test-env: name: codedeploy_fargate_tear-down-test-env requires: - - codedeploy_fargate_test-update-service-job - codedeploy_fargate_test-update-and-wait-service-job terraform-image: "hashicorp/terraform:0.12.16" aws-resource-name-prefix: ${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE} diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index dc4ea057..b96ae6e6 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -998,7 +998,10 @@ commands: fi echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV - when: - condition: << parameters.verify-revision-is-deployed >> + condition: + and: + - << parameters.verify-revision-is-deployed >> + - equal: [ ECS, << parameters.deployment-controller >> ] steps: - verify-revision-is-deployed: family: << parameters.family >> From 14d214cecd39d10eb02560ef387a4bfa6ddf65b0 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Sat, 20 Jun 2020 08:21:51 -0700 Subject: [PATCH 13/18] Add verification timeout as parameter applying to non ecs controllers --- .circleci/config.yml | 1 + src/orb.yml.hbs | 100 +++++++++++++++++++++++++++---------------- 2 files changed, 63 insertions(+), 38 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5eca7fd2..3dd72742 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -686,6 +686,7 @@ workflows: codedeploy-load-balanced-container-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" codedeploy-load-balanced-container-port: 8080 verify-revision-is-deployed: true + verification-timeout: "12m" post_steps: - test-deployment: service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index b96ae6e6..21ce1405 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -275,6 +275,12 @@ jobs: before the max number of polling attempts is reached. type: boolean default: false + verification-timeout: + description: | + The maximum amount of time to wait for a blue/green deployment to complete before timing out. + Only in use when the deployment controller is the blue/green deployment type. + type: string + default: "10m" max-poll-attempts: description: | The maximum number of attempts to poll the deployment status before giving up. @@ -322,6 +328,7 @@ jobs: poll-interval: << parameters.poll-interval >> fail-on-verification-timeout: << parameters.fail-on-verification-timeout >> skip-task-definition-registration: << parameters.skip-task-definition-registration >> + verification-timeout: << parameters.verification-timeout >> update-task-definition: docker: - image: << parameters.docker-image-for-job >> @@ -672,6 +679,7 @@ commands: done echo "Stopped waiting for deployment to be stable - please check the status of << parameters.task-definition-arn >> on the AWS ECS console." <<# parameters.fail-on-verification-timeout >>exit 1<> + update-task-definition: description: Registers a task definition based on the last task definition, except with the Docker image/tag names and environment variables of the containers @@ -914,6 +922,12 @@ commands: before the max number of polling attempts is reached. type: boolean default: false + verification-timeout: + description: | + The maximum amount of time to wait for a blue/green deployment to complete before timing out. + Only in use when the deployment controller is the blue/green deployment type. + type: string + default: "10m" max-poll-attempts: description: | The maximum number of attempts to poll the deployment status before giving up. @@ -957,46 +971,56 @@ commands: --output text \ --query 'taskDefinition.taskDefinitionArn') echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV - - run: - name: Update service with registered task definition - command: | - set -o noglob - DEPLOYMENT_CONTROLLER="$(echo << parameters.deployment-controller >>)" + - when: + condition: + - not: + equal: [ "ECS", << parameters.deployment-controller >> ] + steps: + - run: + name: Update ECS Blue/Green service with registered task definition. + command: | + set -o noglob + DEPLOYMENT_CONTROLLER="$(echo << parameters.deployment-controller >>)" + DEPLOYED_REVISION="${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" + DEPLOYMENT_ID=$(aws deploy create-deployment \ + --application-name "<< parameters.codedeploy-application-name >>" \ + --deployment-group-name "<< parameters.codedeploy-deployment-group-name >>" \ + --revision "{\"revisionType\": \"AppSpecContent\", \"appSpecContent\": {\"content\": \"{\\\"version\\\": 1, \\\"Resources\\\": [{\\\"TargetService\\\": {\\\"Type\\\": \\\"AWS::ECS::Service\\\", \\\"Properties\\\": {\\\"TaskDefinition\\\": \\\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\\\", \\\"LoadBalancerInfo\\\": {\\\"ContainerName\\\": \\\"<< parameters.codedeploy-load-balanced-container-name >>\\\", \\\"ContainerPort\\\": << parameters.codedeploy-load-balanced-container-port >>}}}}]}\"}}" \ + --query deploymentId) + echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" + if [ "<< parameters.verify-revision-is-deployed >>" == "true" ]; then + echo "Waiting for deployment to succeed." + if $(aws deploy wait deployment-successful --deployment-id ${DEPLOYMENT_ID}); then + echo "Deployment succeeded." + else + echo "Deployment failed." + fi + echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV + no_output_timeout: << parameters.verification-timeout >> + - when: + condition: + - equal: [ "ECS", << parameters.deployment-controller >> ] + steps: + - run: + name: Update service with registered task definition + command: | + set -o noglob + SERVICE_NAME="$(echo << parameters.service-name >>)" - if [ "${DEPLOYMENT_CONTROLLER}" = "CODE_DEPLOY" ]; then - DEPLOYED_REVISION="${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" - DEPLOYMENT_ID=$(aws deploy create-deployment \ - --application-name "<< parameters.codedeploy-application-name >>" \ - --deployment-group-name "<< parameters.codedeploy-deployment-group-name >>" \ - --revision "{\"revisionType\": \"AppSpecContent\", \"appSpecContent\": {\"content\": \"{\\\"version\\\": 1, \\\"Resources\\\": [{\\\"TargetService\\\": {\\\"Type\\\": \\\"AWS::ECS::Service\\\", \\\"Properties\\\": {\\\"TaskDefinition\\\": \\\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\\\", \\\"LoadBalancerInfo\\\": {\\\"ContainerName\\\": \\\"<< parameters.codedeploy-load-balanced-container-name >>\\\", \\\"ContainerPort\\\": << parameters.codedeploy-load-balanced-container-port >>}}}}]}\"}}" \ - --query deploymentId) - echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" - if [ "<< parameters.verify-revision-is-deployed >>" == "true" ]; then - echo "Waiting for deployment to succeed." - if $(aws deploy wait deployment-successful --deployment-id ${DEPLOYMENT_ID}); then - echo "Deployment succeeded." - else - echo "Deployment failed." - fi + if [ -z "${SERVICE_NAME}" ]; then + SERVICE_NAME="$(echo << parameters.family >>)" fi - else - SERVICE_NAME="$(echo << parameters.service-name >>)" - - if [ -z "${SERVICE_NAME}" ]; then - SERVICE_NAME="$(echo << parameters.family >>)" - fi - if [ "<< parameters.force-new-deployment >>" == "true" ]; then - set -- "$@" --force-new-deployment - fi - DEPLOYED_REVISION=$(aws ecs update-service \ - --cluster "<< parameters.cluster-name >>" \ - --service "${SERVICE_NAME}" \ - --task-definition "${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" \ - --output text \ - --query service.taskDefinition \ - "$@") - fi - echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV + if [ "<< parameters.force-new-deployment >>" == "true" ]; then + set -- "$@" --force-new-deployment + fi + DEPLOYED_REVISION=$(aws ecs update-service \ + --cluster "<< parameters.cluster-name >>" \ + --service "${SERVICE_NAME}" \ + --task-definition "${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" \ + --output text \ + --query service.taskDefinition \ + "$@") + echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV - when: condition: and: From 87f5c62236346315c23e31e6bb2d0e0b1389ed91 Mon Sep 17 00:00:00 2001 From: Alek Hrycaiko Date: Sat, 20 Jun 2020 08:25:52 -0700 Subject: [PATCH 14/18] Revert not equal into equals Code deploy --- src/orb.yml.hbs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 21ce1405..0a5a56fd 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -973,8 +973,7 @@ commands: echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV - when: condition: - - not: - equal: [ "ECS", << parameters.deployment-controller >> ] + - equal: [ "CODE_DEPLOY", << parameters.deployment-controller >> ] steps: - run: name: Update ECS Blue/Green service with registered task definition. From 42f5bc8d92b7ffd86eb50377e9502d8f5c27095f Mon Sep 17 00:00:00 2001 From: Stella Lok Date: Fri, 7 Aug 2020 13:29:21 +0800 Subject: [PATCH 15/18] fix some syntax issues --- .circleci/config.yml | 2 +- src/orb.yml.hbs | 44 ++++++++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3dd72742..08f68c6f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -687,7 +687,7 @@ workflows: codedeploy-load-balanced-container-port: 8080 verify-revision-is-deployed: true verification-timeout: "12m" - post_steps: + post-steps: - test-deployment: service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 0a5a56fd..9b277629 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -972,8 +972,8 @@ commands: --query 'taskDefinition.taskDefinitionArn') echo "export CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN='${TASK_DEFINITION_ARN}'" >> $BASH_ENV - when: - condition: - - equal: [ "CODE_DEPLOY", << parameters.deployment-controller >> ] + condition: + equal: [ "CODE_DEPLOY", << parameters.deployment-controller >> ] steps: - run: name: Update ECS Blue/Green service with registered task definition. @@ -998,28 +998,28 @@ commands: no_output_timeout: << parameters.verification-timeout >> - when: condition: - - equal: [ "ECS", << parameters.deployment-controller >> ] - steps: + equal: [ "ECS", << parameters.deployment-controller >> ] + steps: - run: - name: Update service with registered task definition - command: | - set -o noglob - SERVICE_NAME="$(echo << parameters.service-name >>)" + name: Update service with registered task definition + command: | + set -o noglob + SERVICE_NAME="$(echo << parameters.service-name >>)" - if [ -z "${SERVICE_NAME}" ]; then - SERVICE_NAME="$(echo << parameters.family >>)" - fi - if [ "<< parameters.force-new-deployment >>" == "true" ]; then - set -- "$@" --force-new-deployment - fi - DEPLOYED_REVISION=$(aws ecs update-service \ - --cluster "<< parameters.cluster-name >>" \ - --service "${SERVICE_NAME}" \ - --task-definition "${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" \ - --output text \ - --query service.taskDefinition \ - "$@") - echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV + if [ -z "${SERVICE_NAME}" ]; then + SERVICE_NAME="$(echo << parameters.family >>)" + fi + if [ "<< parameters.force-new-deployment >>" == "true" ]; then + set -- "$@" --force-new-deployment + fi + DEPLOYED_REVISION=$(aws ecs update-service \ + --cluster "<< parameters.cluster-name >>" \ + --service "${SERVICE_NAME}" \ + --task-definition "${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}" \ + --output text \ + --query service.taskDefinition \ + "$@") + echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV - when: condition: and: From a15edc2b25283a3970fdbca77c2cbbf3c7f495d9 Mon Sep 17 00:00:00 2001 From: Stella Lok Date: Fri, 7 Aug 2020 14:58:35 +0800 Subject: [PATCH 16/18] fix bash syntax issue --- src/orb.yml.hbs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 9b277629..4753f337 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -988,12 +988,13 @@ commands: --query deploymentId) echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" if [ "<< parameters.verify-revision-is-deployed >>" == "true" ]; then - echo "Waiting for deployment to succeed." + echo "Waiting for deployment to succeed." if $(aws deploy wait deployment-successful --deployment-id ${DEPLOYMENT_ID}); then echo "Deployment succeeded." else echo "Deployment failed." fi + fi echo "export CCI_ORB_AWS_ECS_DEPLOYED_REVISION='${DEPLOYED_REVISION}'" >> $BASH_ENV no_output_timeout: << parameters.verification-timeout >> - when: From 60bc7048ef23b8699d43fda4428cf920de2b51f2 Mon Sep 17 00:00:00 2001 From: Stella Lok Date: Fri, 7 Aug 2020 16:22:04 +0800 Subject: [PATCH 17/18] strip quotes from deployment id --- src/orb.yml.hbs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/orb.yml.hbs b/src/orb.yml.hbs index 4753f337..593892fd 100644 --- a/src/orb.yml.hbs +++ b/src/orb.yml.hbs @@ -985,7 +985,8 @@ commands: --application-name "<< parameters.codedeploy-application-name >>" \ --deployment-group-name "<< parameters.codedeploy-deployment-group-name >>" \ --revision "{\"revisionType\": \"AppSpecContent\", \"appSpecContent\": {\"content\": \"{\\\"version\\\": 1, \\\"Resources\\\": [{\\\"TargetService\\\": {\\\"Type\\\": \\\"AWS::ECS::Service\\\", \\\"Properties\\\": {\\\"TaskDefinition\\\": \\\"${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}\\\", \\\"LoadBalancerInfo\\\": {\\\"ContainerName\\\": \\\"<< parameters.codedeploy-load-balanced-container-name >>\\\", \\\"ContainerPort\\\": << parameters.codedeploy-load-balanced-container-port >>}}}}]}\"}}" \ - --query deploymentId) + --query deploymentId \ + --output text) echo "Created CodeDeploy deployment: $DEPLOYMENT_ID" if [ "<< parameters.verify-revision-is-deployed >>" == "true" ]; then echo "Waiting for deployment to succeed." From 6ae351e4e3de645bbc0df7ea8de9b23338165612 Mon Sep 17 00:00:00 2001 From: Stella Lok Date: Fri, 7 Aug 2020 17:01:43 +0800 Subject: [PATCH 18/18] fix test --- .circleci/config.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 08f68c6f..d87d0093 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -664,10 +664,7 @@ workflows: - test-deployment: service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" - delete-load-balancer: true - - delete-service: - service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" - cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" + delete-load-balancer: false - aws-ecs/deploy-service-update: name: codedeploy_fargate_test-update-and-wait-service-job @@ -692,6 +689,9 @@ workflows: service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" delete-load-balancer: true + - delete-service: + service-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-service" + cluster-name: "${AWS_RESOURCE_NAME_PREFIX_CODEDEPLOY_FARGATE}-cluster" - tear-down-test-env: name: ec2_tear-down-test-env requires: