Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Deployment Controller #34

Merged
merged 17 commits into from
Oct 6, 2019
Merged

Conversation

enokawa
Copy link
Contributor

@enokawa enokawa commented Sep 14, 2019

Add Deployment Controller for Blue/Green Deployment.
https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-bluegreen.html

Ref: #33

I confirmed that B/G Deployment was successful using my own orb.
Update service with registered task definition

#!/bin/bash -eo pipefail
DEPLOYMENT_CONTROLLER="$(echo CODE_DEPLOY)"

if [ "${DEPLOYMENT_CONTROLLER}" = "CODE_DEPLOY" ]; then
    DEPLOYED_REVISION=$(aws deploy create-deployment \
        --application-name "AppECS-sample-cluster-sample" \
        --deployment-group-name "DgpECS-sample-cluster-sample" \
        --revision '{"revisionType": "AppSpecContent", "appSpecContent": {"content": "{\"version\": 1, \"Resources\": [{\"TargetService\": {\"Type\": \"AWS::ECS::Service\", \"Properties\": {\"TaskDefinition\": \"'${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}'\", \"LoadBalancerInfo\": {\"ContainerName\": \"nginx\", \"ContainerPort\": 80}}}}]}"}}' \
        --query deploymentId)
else
  SERVICE_NAME="$(echo sample)"

  if [ -z "${SERVICE_NAME}" ]; then
      SERVICE_NAME="$(echo sample-app)"
  fi
  DEPLOYED_REVISION=$(aws ecs update-service \
      --cluster "sample-cluster" \
      --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

This is .circleci/config.yml .

version: 2.1
orbs:
  aws-ecr: circleci/aws-ecr@6.2.0
  aws-ecs: enokawa/aws-ecs@0.0.1
workflows:
  build_and_push_image:
    jobs:
      - aws-ecr/build-and-push-image:
          name: nginx
          account-url: AWS_ECR_ACCOUNT_URL
          aws-access-key-id: AWS_ACCESS_KEY_ID
          aws-secret-access-key: AWS_SECRET_ACCESS_KEY
          dockerfile: docker/nginx/Dockerfile
          region: AWS_REGION
          repo: sample/nginx
          tag: "${CIRCLE_SHA1}"
      - aws-ecr/build-and-push-image:
          name: php-fpm
          account-url: AWS_ECR_ACCOUNT_URL
          aws-access-key-id: AWS_ACCESS_KEY_ID
          aws-secret-access-key: AWS_SECRET_ACCESS_KEY
          dockerfile: docker/php-fpm/Dockerfile
          region: AWS_REGION
          repo: sample/php-fpm
          tag: "${CIRCLE_SHA1}"
      - aws-ecs/deploy-service-update:
          requires:
            - nginx
            - php-fpm
          family: 'sample-app'
          service-name: 'sample'
          cluster-name: 'sample-cluster'
          deployment-controller: 'CODE_DEPLOY'
          application-name: 'AppECS-sample-cluster-sample'
          deployment-group-name: 'DgpECS-sample-cluster-sample'
          container-name-for-code-deploy: 'nginx'
          container-port-for-code-deploy: 80
          container-image-name-updates: 'container=nginx,image-and-tag=${AWS_ECR_ACCOUNT_URL}/sample/nginx:${CIRCLE_SHA1},container=php-fpm,image-and-tag=${AWS_ECR_ACCOUNT_URL}/sample/php-fpm:${CIRCLE_SHA1}'

@lokst
Copy link
Contributor

lokst commented Sep 16, 2019

@enokawa Thank you so much for taking this on and do let us know once the PR is ready for review 🙂

@enokawa enokawa changed the title [WIP] Add Deployment Controller Add Deployment Controller Sep 19, 2019
@enokawa
Copy link
Contributor Author

enokawa commented Sep 19, 2019

@lokst Please code review!!

@lokst
Copy link
Contributor

lokst commented Sep 20, 2019

@enokawa Thank you, I'll review this as soon as possible!

src/orb.yml.hbs Outdated
deployment-controller:
description:
"The deployment controller to use for the service. Defaulted to ECS"
type: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great if the type could be an enum: https://circleci.com/docs/2.0/reusing-config/#enum

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 4da210a .

src/orb.yml.hbs Outdated
"The deployment controller to use for the service. Defaulted to ECS"
type: string
default: "ECS"
application-name:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to codedeploy-application-name for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by e4fd0ed .

src/orb.yml.hbs Outdated
default: "ECS"
application-name:
description:
"The name of an AWS CodeDeploy application."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add some more details to the description to clarify the purpose of this parameter:

description: |
  The name of the AWS CodeDeploy application used for the deployment.
  Only effective when the deployment-controller parameter value is "C
ODE_DEPLOY".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 302f398 .

src/orb.yml.hbs Outdated
"The name of an AWS CodeDeploy application."
type: string
default: ""
deployment-group-name:
Copy link
Contributor

@lokst lokst Sep 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to codedeploy-deployment-group-name for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 80b9c36 .

src/orb.yml.hbs Outdated
default: ""
deployment-group-name:
description:
"The name of an AWS CodeDeploy deployment group."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add some more details to the description to clarify the purpose of this parameter, like this:

description: |
  The name of the AWS CodeDeploy deployment group used for the deployment.
  Only effective when the deployment-controller parameter value is "C
ODE_DEPLOY".

Copy link
Contributor Author

@enokawa enokawa Oct 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by a84730b .

src/orb.yml.hbs Outdated
"The name of an AWS CodeDeploy deployment group."
type: string
default: ""
container-name-for-code-deploy:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to codedeploy-load-balanced-container-name for clarity? (Please feel free to suggest a better name!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by adcb99c .

src/orb.yml.hbs Outdated
default: ""
container-name-for-code-deploy:
description:
"The name of the container for CodeDeploy."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add some more details to the description to clarify the purpose of this parameter, like this:

description: |
  The name of the container to be load-balanced via AWS CodeDeploy.
  Only effective when the deployment-controller parameter value is "C
ODE_DEPLOY".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 3bd0e61 .

src/orb.yml.hbs Outdated
"The name of the container for CodeDeploy."
type: string
default: ""
container-port-for-code-deploy:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be changed to codedeploy-load-balanced-container-port for clarity? (Please feel free to suggest a better name!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by 102d851 .

src/orb.yml.hbs Outdated
default: ""
container-port-for-code-deploy:
description:
"The port of the container for CodeDeploy."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add some more details to the description to clarify the purpose of this parameter, like this:

description: |
  The port of the container to be load-balanced via AWS CodeDeploy.
  Only effective when the deployment-controller parameter value is "C
ODE_DEPLOY".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by b7e161f .

--application-name "<< parameters.application-name >>" \
--deployment-group-name "<< parameters.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.container-name-for-code-deploy >>\", \"ContainerPort\": << parameters.container-port-for-code-deploy >>}}}}]}"}}' \
--query deploymentId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of the following changes? That way, the verify-revision-is-deployed parameter should still be able to work if set to true.

DEPLOYED_REVISION="${CCI_ORB_AWS_ECS_REGISTERED_TASK_DFN}"
DEPLOYMENT_ID=$(aws deploy create-deployment ...)

and also adding echo "Created CodeDeploy deployment: $DEPLOYMENT_ID"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great changes! I fixed by ae19b28 .

Copy link
Contributor

@lokst lokst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@enokawa Thanks so much for this PR. I tested them and found that they work well. I've made some suggestions here and would love if you can review them!

@enokawa
Copy link
Contributor Author

enokawa commented Oct 1, 2019

@lokst Thank you for your review!
I'll fix them.

@enokawa
Copy link
Contributor Author

enokawa commented Oct 1, 2019

@lokst I Fixed them. Please code review again.
And also big thanks for create some tests!!

src/orb.yml.hbs Outdated
@@ -530,24 +535,28 @@ commands:
"The deployment controller to use for the service. Defaulted to ECS"
type: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed out on this in my earlier review. Could this be changed to an enum too? 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I missed too. Fixed by 500ac8c .

Copy link
Contributor

@lokst lokst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your changes! I gave this a test and realized that some changes will be required to the verify-revision-is-deployed command in order to support verification for blue/green deployments. Hence could you also update the description of theverify-revision-is-deployed command and verify-revision-is-deployed parameter to add something like "Does not support ECS services that are of the blue/green deployment type." (Of course, feel free to add support for verify-revision-is-deployed: true if you like, in this PR or another)

@lokst
Copy link
Contributor

lokst commented Oct 2, 2019

Thanks @enokawa, could you also update the description of the verify-revision-is- deployedcommand and verify-revision-is-deployed parameter to add something like "Does not support ECS services that are of the blue/green deployment type", and also pull in the latest changes in master branch?

@enokawa
Copy link
Contributor Author

enokawa commented Oct 3, 2019

@lokst Sorry I'm late. I was update verify-revision-is-deployed command and parameter description.
And also I merged master branch changes.

@enokawa
Copy link
Contributor Author

enokawa commented Oct 3, 2019

And I will add support for verify-revision-is-deployed another PR!!

@enokawa enokawa requested a review from lokst October 3, 2019 12:40
@lokst
Copy link
Contributor

lokst commented Oct 4, 2019

Thanks @enokawa! I am out of office most of this week and will review this once I'm back next week!

@lokst lokst merged commit cc110ab into CircleCI-Public:master Oct 6, 2019
@lokst lokst added the enhancement New feature or request label Oct 6, 2019
@lokst lokst added this to the 0.0.12 milestone Oct 6, 2019
@lokst
Copy link
Contributor

lokst commented Oct 6, 2019

@enokawa Thanks so much for contributing this new feature of blue/green deployment support! Your changes are now available in version 0.0.12 of the orb!

@enokawa
Copy link
Contributor Author

enokawa commented Oct 7, 2019

@lokst Thanks so much!!
I'll try version 0.0.12 of the orb soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants