Skip to content

Commit

Permalink
Merge pull request #3 from SparkPost/TR-4781
Browse files Browse the repository at this point in the history
TR-4781 Add wait for deployment completion feature by checking ECS service stability
  • Loading branch information
0xkalvin authored Dec 20, 2023
2 parents 6ec49ac + 50cf5a3 commit f8f6ffb
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion ecs-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ VERBOSE=false
TAGVAR=false
TAGONLY=""
ENABLE_ROLLBACK=false
WAIT_COMPLETION=false
AWS_CLI=$(which aws)
AWS_ECS="$AWS_CLI --output json ecs"

Expand Down Expand Up @@ -50,6 +51,7 @@ Optional arguments:
-to | --tag-only New tag to apply to all images defined in the task (multi-container task). If provided this will override value specified in image name argument.
--max-definitions Number of Task Definition Revisions to persist before deregistering oldest revisions.
--enable-rollback Rollback task definition if new version is not running before TIMEOUT
--wait-completion Wait for the full deployment completion by checking if the service is stable
-v | --verbose Verbose output
--version Display the version
Expand Down Expand Up @@ -407,6 +409,38 @@ function waitForGreenDeployment {
fi
}

function waitForDeplomentCompletion {
echo "Waiting for deployment completion until service is stable"

WAIT="true"
DEPLOYMENT_SUCCESS="false"

while [ "${WAIT}" != "false" ]
do

set +e
$AWS_ECS wait services-stable --cluster $CLUSTER --services $SERVICE
DEPLOYMENT_EXIT_CODE=$(echo $?)
set -e

if [[ "$DEPLOYMENT_EXIT_CODE" == 0 ]]; then
DEPLOYMENT_SUCCESS="true"
WAIT="false"
echo "Deployment completed successfully"
else
WAIT="false"
echo "Deployment timeout"
fi
done

if [[ "${DEPLOYMENT_SUCCESS}" != "true" ]]; then
if [[ "${ENABLE_ROLLBACK}" != "false" ]]; then
rollback
fi
exit 1
fi
}

######################################################
# When not being tested, run application as expected #
######################################################
Expand Down Expand Up @@ -500,6 +534,9 @@ if [ "$BASH_SOURCE" == "$0" ]; then
--enable-rollback)
ENABLE_ROLLBACK=true
;;
--wait-completion)
WAIT_COMPLETION=true
;;
-v|--verbose)
VERBOSE=true
;;
Expand Down Expand Up @@ -549,7 +586,11 @@ if [ "$BASH_SOURCE" == "$0" ]; then
else
updateService

waitForGreenDeployment
if [ $WAIT_COMPLETION == true ]; then
waitForDeplomentCompletion
else
waitForGreenDeployment
fi
fi

if [[ "$AWS_ASSUME_ROLE" != false ]]; then
Expand Down

0 comments on commit f8f6ffb

Please sign in to comment.