Skip to content

Commit 37797f3

Browse files
committed
fix(ci): fail deployment action when deployment is rolled back
Problem: When ECS's circuit breaker mechanism rolls back a failing deploy, the deploy task github action will exit with a success code when infact the deployment was not successful. In order to identify unsuccessful service updates, we want the github action to fail. At time of writing, there is no option elicit this behavior from the aws-actions/amazon-ecs-deploy-task-definition@v2 action. Instead, we must check that the services current task definition is the one we attempted to roll out. See discussion in aws-actions/amazon-ecs-deploy-task-definition#191
1 parent bf35e3e commit 37797f3

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

.github/workflows/callable-deploy-ecs.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,31 @@ jobs:
6969
echo "$( jq --arg image "${{ steps.config.outputs.TARGET_IMAGE_W_DIGEST }}" '.containerDefinitions |= map((select(.name == "gateway") | .image) |= $image)' task.json )" > task.json
7070
cat task.json
7171
72-
7372
- name: Deploy Amazon ECS task definition
73+
id: ecs-deploy
7474
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
7575
with:
7676
task-definition: task.json
7777
service: ${{ vars.ECS_SERVICE }}
7878
cluster: ${{ vars.ECS_CLUSTER }}
7979
wait-for-service-stability: true
80-
propagate-tags: SERVICE
80+
propagate-tags: SERVICE
81+
82+
- name: Verify deploy
83+
id: check-deployment
84+
run: |
85+
TASK_DEF_EXPECTED=${{ steps.ecs-deploy.outputs.task-definition-arn }}
86+
TASK_DEF_CURRENT=$(
87+
aws ecs describe-services \
88+
--cluster ${{ vars.ECS_CLUSTER }} \
89+
--services ${{ vars.ECS_SERVICE }} \
90+
--query services[0].deployments[0].taskDefinition \
91+
| jq -r "."
92+
)
93+
echo "Task Arn - Current: $TASK_DEF_CURRENT"
94+
echo "Task Arn - Expected: $TASK_DEF_EXPECTED"
95+
if [ "$TASK_DEF_CURRENT" != "$TASK_DEF_EXPECTED" ]; then
96+
echo "Current task arn does not match the expected task arn."
97+
echo "The deployment may have been rolled back or been deposed by a more recent deployment attempt"
98+
exit 1
99+
fi

0 commit comments

Comments
 (0)