Skip to content

Commit

Permalink
Merge pull request silinternational#152 from silinternational/develop
Browse files Browse the repository at this point in the history
 Add flag for using the latest task definition
  • Loading branch information
fillup authored Aug 13, 2018
2 parents b23b574 + da39f64 commit 2470057
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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
--use-latest-task-def Will use the most recently created task definition as it's base, rather than the last used.
--force-new-deployment Force a new deployment of the service. Default is false.
--skip-deployments-check Skip deployments check for services that take too long to drain old tasks
--run-task Run created task now. If you set this, service-name are not needed.
Expand Down Expand Up @@ -114,7 +115,7 @@ _Naturally, enough computing resources must be available in the ECS cluster for
Consequently, all that is needed to deploy a new version of an application is to update the Service which is running its
Tasks to point at a new version of the Task Definition. `ecs-deploy` uses the python `aws` utility to do this. It,

* Pulls the JSON representation of the in-use Task Definition
* Pulls the JSON representation of the in-use Task Definition; or the most recently created if using `--use-latest-task-def`
* Edits it
* Defines a new version, with the changes
* Updates the Service to use the new version
Expand Down
20 changes: 18 additions & 2 deletions 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
USE_MOST_RECENT_TASK_DEFINITION=false
AWS_CLI=$(which aws)
AWS_ECS="$AWS_CLI --output json ecs"
FORCE_NEW_DEPLOYMENT=false
Expand Down Expand Up @@ -54,6 +55,7 @@ Optional arguments:
--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.
--use-latest-task-def Will use the most recently created task definition as it's base, rather than the last used.
--skip-deployments-check Skip deployments check for services that take too long to drain old tasks
--run-task Run created task now. If you set this, service-name are not needed.
-v | --verbose Verbose output
Expand Down Expand Up @@ -273,6 +275,17 @@ function getCurrentTaskDefinition() {
if [ $SERVICE != false ]; then
# Get current task definition arn from service
TASK_DEFINITION_ARN=`$AWS_ECS describe-services --services $SERVICE --cluster $CLUSTER | jq -r .services[0].taskDefinition`
TASK_DEFINITION=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION_ARN`

# For rollbacks
LAST_USED_TASK_DEFINITION_ARN=$TASK_DEFINITION_ARN

if [ $USE_MOST_RECENT_TASK_DEFINITION != false ]; then
# Use the most recently created TD of the family; rather than the most recently used.
TASK_DEFINITION_FAMILY=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION_ARN | jq -r .taskDefinition.family`
TASK_DEFINITION=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION_FAMILY`
TASK_DEFINITION_ARN=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION_FAMILY | jq -r .taskDefinition.taskDefinitionArn`
fi
elif [ $TASK_DEFINITION != false ]; then
# Get current task definition arn from family[:revision] (or arn)
TASK_DEFINITION_ARN=`$AWS_ECS describe-task-definition --task-def $TASK_DEFINITION | jq -r .taskDefinition.taskDefinitionArn`
Expand Down Expand Up @@ -330,8 +343,8 @@ function registerNewTaskDefinition() {
}

function rollback() {
echo "Rolling back to ${TASK_DEFINITION_ARN}"
$AWS_ECS update-service --cluster $CLUSTER --service $SERVICE --task-definition $TASK_DEFINITION_ARN > /dev/null
echo "Rolling back to ${LAST_USED_TASK_DEFINITION_ARN}"
$AWS_ECS update-service --cluster $CLUSTER --service $SERVICE --task-definition $LAST_USED_TASK_DEFINITION_ARN > /dev/null
}

function updateServiceForceNewDeployment() {
Expand Down Expand Up @@ -549,6 +562,9 @@ if [ "$BASH_SOURCE" == "$0" ]; then
--enable-rollback)
ENABLE_ROLLBACK=true
;;
--use-latest-task-def)
USE_MOST_RECENT_TASK_DEFINITION=true
;;
--force-new-deployment)
FORCE_NEW_DEPLOYMENT=true
;;
Expand Down

0 comments on commit 2470057

Please sign in to comment.