Skip to content

Commit

Permalink
EPBR-6353 adds check service status build spec
Browse files Browse the repository at this point in the history
This buildspec and shell script is to be used by the pipeline when rolling deployments are not enable. This enables the code pipeline to check the service has been successfully restarted before the next stage runs
  • Loading branch information
barryhalper committed Aug 14, 2024
1 parent 59641f4 commit 6484bf5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
15 changes: 15 additions & 0 deletions buildspec/check_service_status.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 0.2

phases:
pre_build:
commands:
- aws --version


build:
commands:
- bash ./buildspec/assume_role.sh arn:aws:iam::$AWS_ACCOUNT_ID:role/ci-server this_profile
- bash ./scripts/check_deployment_status.sh this_profile $CLUSTER_NAME $SERVICE_NAME



4 changes: 2 additions & 2 deletions buildspec/deploy_to_cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ phases:

post_build:
commands:
- bash ./buildspec/assume_role.sh arn:aws:iam::$AWS_ACCOUNT_ID:role/ci-server stage
- aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment --profile stage
- bash ./buildspec/assume_role.sh arn:aws:iam::$AWS_ACCOUNT_ID:role/ci-server this_profile
- aws ecs update-service --cluster $CLUSTER_NAME --service $SERVICE_NAME --force-new-deployment --profile this_profile
29 changes: 29 additions & 0 deletions scripts/check_deployment_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

CLUSTER_NAME=$1
SERVICE_NAME=$2


#
STATUS=$(aws ecs describe-services --services $SERVICE_NAME --cluster $CLUSTER_NAME | jq -rc '.services[0].deployments[0].rolloutState' )
##echo "${STATUS}"
##if [[ $STATUS == "COMPLETED" ]]; then
## echo "done"
##fi
#exit 0

while [[ $STATUS == "IN_PROGRESS" ]]; do
STATUS=$(aws ecs describe-services --services $SERVICE_NAME --cluster $CLUSTER_NAME | jq -rc '.services[0].deployments[0].rolloutState' )
echo "${STATUS} << WAITING FOR RESTART STATUS TO REACH COMPLETED"
sleep 20
done

if [[ $STATUS == "COMPLETED" ]]; then
echo "SERVICE RESTART HAS COMPLETED SUCCESSFULLY"
exit 0
fi



echo 'SERVICE RESTART HAS FAILED'
exit 1

0 comments on commit 6484bf5

Please sign in to comment.