Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #19 from AssemblyAI/add-blue-green-support
Browse files Browse the repository at this point in the history
Add blue green support
  • Loading branch information
chilledornaments authored Jun 18, 2021
2 parents e78186e + c3c3950 commit 70cea21
Show file tree
Hide file tree
Showing 19 changed files with 1,163 additions and 141 deletions.
10 changes: 9 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ export PLUGIN_AWS_REGION=us-east-2
export PLUGIN_SERVICE=
export PLUGIN_CLUSTER=
export PLUGIN_CONTAINER=
export PLUGIN_IMAGE=
export PLUGIN_IMAGE=
export PLUGIN_MODE=
export PLUGIN_BLUE_SERVICE=
export PLUGIN_GREEN_SERVICE=
export PLUGIN_MAX_DEPLOY_CHECKS=
export PLUGIN_SCALE_DOWN_PERCENT=
export PLUGIN_SCALE_DOWN_INTERVAL=
export PLUGIN_SCALE_DOWN_WAIT_PERIOD=
export PLUGIN_CHECKS_TO_PASS=
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

`drone-deploy-ecs` is an opinionated Drone plugin for updating a single container within an ECS Task.

During deployment, the plugin retrieves the active Task Definition for a specified ECS Service, creates a new revision of the Task Definition with an updated image for a specified container, updates the Service to use the new Task Definition, and waits for the deployment to complete.
This plugin has support for two deployment modes: rolling and blue / green.

During a rolling deployment, the plugin retrieves the active Task Definition for a specified ECS Service, creates a new revision of the Task Definition with an updated image for a specified container, updates the Service to use the new Task Definition, and waits for the deployment to complete.

A blue / green deployment is similar to a rolling deployment. The key difference is that once the number of running green tasks matches the number of desired green tasks, the blue service is scaled down. It's important to note that this plugin _only_ uses desired vs running to determine deployment health. It will not check the health of a target in a target group, for example

[ECR Link](https://gallery.ecr.aws/assemblyai/drone-deploy-ecs)

## Important Notes

This plugin cannot update different containers within the same Task Definition simultaneously. It will only update the image for a single container within a Task Defintion
This plugin cannot update multiple containers within the same Task Definition simultaneously. It will only update the image for a single container within a Task Defintion

The ECS Service must use the `ECS` deployment controller.

~~This plugin will not rollback for you. For rollbacks, use a [deployment circuit breaker](https://aws.amazon.com/blogs/containers/announcing-amazon-ecs-deployment-circuit-breaker/).~~

## Requirements

Expand All @@ -28,10 +31,13 @@ The ECS Service being deployed to must use the `ECS` deployment controller.
- `ecs:DescribeServices` on any services this tool will modify
- `ecs:UpdateService` on any services this tool will modify
- `ecs:RegisterTaskDefinition` on `*`

- `application-autoscaling:DescribeScalableTargets` on `*`
- `application-autoscaling:RegisterScalableTarget` on `*` if you plan on using a blue/green deployment

## Example usage

### Rolling Deployment

```yaml
---
kind: pipeline
Expand All @@ -41,6 +47,7 @@ steps:
- name: deploy
image: public.ecr.aws/assemblyai/drone-deploy-ecs
settings:
mode: rolling
aws_region: us-east-2
# The name of the ECS service
service: webapp
Expand All @@ -51,4 +58,59 @@ steps:
# The image to deploy
image: myorg/nginx-${DRONE_COMMIT_SHA}
max_deploy_checks: 10
```
```
### Blue / Green
Blue / Green deployments will work with services that use Application Autoscaling and those that do not.
One service must have a desired count of 0, the other must have a desired count > 0.
It does not matter which service is set for `blue_service` or `green_service`. The plugin will use the service with a desired count of 0 as the green service. This is simply a way to define which two services the plugin should modify.

Once the number of running containers equals the number of desired containers for the green service, the plugin will begin scaling down the blue service by `scale_down_percent`.


```yml
---
kind: pipeline
name: deploy
steps:
- name: deploy
image: public.ecr.aws/assemblyai/drone-deploy-ecs
settings:
mode: blue-green
aws_region: us-east-2
# The name of the green ECS service
green_service: webapp-green
# The name of the blue ECS service
blue_service: webapp-blue
# The name of the ECS cluster that the service is in
cluster: dev-ecs-cluster
# The name of the container to update
container: nginx
# The image to deploy
image: myorg/nginx-${DRONE_COMMIT_SHA}
# How many times to check rollout status before failing
max_deploy_checks: 10
# Percent of instances to scale down blue service by
scale_down_percent: 50
# Seconds to wait between scale down events
scale_down_interval: 600
# Number of seconds between scaling up green service and scaling down blue
# This is useful if your application takes some time to become healthy
scale_down_wait_period: 10
# Number of times running count must equal desired count in order to mark green deployment as a success
checks_to_pass: 2
```


## TODO

- Code cleanup
- Better `settings` documentation
- Tests
- Better, more consistent logging
- Update `pkg/deploy` functions to use `deploy.DeployConfig`
- Fix `scaleDownInPercentages()` bug
Loading

0 comments on commit 70cea21

Please sign in to comment.