Skip to content

Commit

Permalink
Merge pull request silinternational#141 from kakakakakku/support-forc…
Browse files Browse the repository at this point in the history
…e-new-deployment

Supported "--force-new-deployment" option
  • Loading branch information
fillup authored Jul 24, 2018
2 parents 2a4f775 + 9f2984d commit 8dbb19c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Usage
Max definitions causes all task revisions not matching criteria to be deregistered, even if they're created manually.
Script will only perform deregistration if deployment succeeds.
--enable-rollback Rollback task definition if new version is not running before TIMEOUT
--force-new-deployment Force a new deployment of the service. Default is false.
-v | --verbose Verbose output
--version Display the version

Expand Down
22 changes: 18 additions & 4 deletions ecs-deploy
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TAGONLY=""
ENABLE_ROLLBACK=false
AWS_CLI=$(which aws)
AWS_ECS="$AWS_CLI --output json ecs"
FORCE_NEW_DEPLOYMENT=false

function usage() {
cat <<EOM
Expand All @@ -38,7 +39,7 @@ Required arguments:
Format: [domain][:port][/repo][/][image][:tag]
Examples: mariadb, mariadb:latest, silintl/mariadb,
silintl/mariadb:latest, private.registry.com:8000/repo/image:tag
--aws-instance-profile Use the IAM role associated with this instance
--aws-instance-profile Use the IAM role associated with this instance
Optional arguments:
-a | --assume-role ARN for AWS Role to assume for ecs-deploy operations.
Expand All @@ -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
--force-new-deployment Force a new deployment of the service. Default is false.
-v | --verbose Verbose output
--version Display the version
Expand Down Expand Up @@ -145,7 +147,7 @@ function assertRequiredArgumentsSet() {
echo "CLUSTER is required. You can pass the value using -c or --cluster"
exit 7
fi
if [ $IMAGE == false ]; then
if [ $IMAGE == false ] && [ $FORCE_NEW_DEPLOYMENT == false ]; then
echo "IMAGE is required. You can pass the value using -i or --image"
exit 8
fi
Expand Down Expand Up @@ -328,6 +330,11 @@ function rollback() {
$AWS_ECS update-service --cluster $CLUSTER --service $SERVICE --task-definition $TASK_DEFINITION_ARN > /dev/null
}

function updateServiceForceNewDeployment() {
echo 'Force a new deployment of the service'
$AWS_ECS update-service --cluster $CLUSTER --service $SERVICE --force-new-deployment > /dev/null
}

function updateService() {
UPDATE_SERVICE_SUCCESS="false"
DEPLOYMENT_CONFIG=""
Expand Down Expand Up @@ -533,6 +540,9 @@ if [ "$BASH_SOURCE" == "$0" ]; then
--enable-rollback)
ENABLE_ROLLBACK=true
;;
--force-new-deployment)
FORCE_NEW_DEPLOYMENT=true
;;
-v|--verbose)
VERBOSE=true
;;
Expand All @@ -552,14 +562,19 @@ if [ "$BASH_SOURCE" == "$0" ]; then
set -x
fi


# Check that required arguments are provided
assertRequiredArgumentsSet

if [[ "$AWS_ASSUME_ROLE" != false ]]; then
assumeRole
fi

# Not required creation of new a task definition
if [ $FORCE_NEW_DEPLOYMENT == true ]; then
updateServiceForceNewDeployment
waitForGreenDeployment
exit 0
fi

# Determine image name
parseImageName
Expand Down Expand Up @@ -589,7 +604,6 @@ if [ "$BASH_SOURCE" == "$0" ]; then
assumeRoleClean
fi


exit 0

fi
Expand Down
1 change: 1 addition & 0 deletions test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ setup() {
SERVICE=true
CLUSTER=true
IMAGE=false
FORCE_NEW_DEPLOYMENT=false
run assertRequiredArgumentsSet
[ $status -eq 8 ]
}
Expand Down

0 comments on commit 8dbb19c

Please sign in to comment.