Skip to content

Commit 79133f8

Browse files
Skip redundant force-deploy when tf-apply already triggered a rollout (#52)
## Summary When tf-apply updates the ECS service (new task def revision), ECS already starts a rolling deployment. The ecs-deploy step was then calling `--force-new-deployment` on top of that, causing **two sequential deployments** and doubling the stabilization wait (~5 min instead of ~2 min). Now checks if a deployment is already in progress (deployment count > 1) and skips the force if so. ## Test plan - [ ] Merge and trigger platform-test-app - [ ] When tf-apply runs (has changes): deploy should say "Deployment already in progress, waiting..." and finish in ~2 min - [ ] When tf-apply is skipped (no changes): deploy should force as before
1 parent 458e08a commit 79133f8

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

scripts/ecs-deploy.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33
#
44
# Forces a new deployment so ECS pulls the latest image for the current
55
# task definition. Does NOT create new task definition revisions — that's
6-
# Terraform's job. This avoids drift between TF-managed task defs
7-
# (with security hardening, volumes, etc.) and deploy-time revisions.
6+
# Terraform's job.
7+
#
8+
# If a deployment is already in progress (e.g. from tf-apply), skips the
9+
# force and just waits for it to stabilize.
810
#
911
# Usage: ecs-deploy.sh
1012
#
1113
# Env: CLUSTER, SERVICE
1214

1315
set -e
1416

15-
echo "Forcing new deployment for ${SERVICE} on ${CLUSTER}..."
16-
aws ecs update-service \
17-
--cluster "$CLUSTER" --service "$SERVICE" \
18-
--force-new-deployment > /dev/null
17+
# Check if a deployment is already rolling out
18+
DEPLOYMENT_COUNT=$(aws ecs describe-services \
19+
--cluster "$CLUSTER" --services "$SERVICE" \
20+
--query 'length(services[0].deployments)' --output text)
21+
22+
if [ "$DEPLOYMENT_COUNT" -gt 1 ]; then
23+
echo "Deployment already in progress (${DEPLOYMENT_COUNT} deployments), waiting..."
24+
else
25+
echo "Forcing new deployment for ${SERVICE} on ${CLUSTER}..."
26+
aws ecs update-service \
27+
--cluster "$CLUSTER" --service "$SERVICE" \
28+
--force-new-deployment > /dev/null
29+
fi
1930

2031
echo "Waiting for service to stabilize..."
2132
aws ecs wait services-stable --cluster "$CLUSTER" --services "$SERVICE"

0 commit comments

Comments
 (0)