Last active
November 1, 2017 16:31
-
-
Save ajbrown/5e361f6792931cbab863db76c2904fb1 to your computer and use it in GitHub Desktop.
EC2 Deployment ServiceUpdate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Deploy a new image to an ECS service by creating a new task revision | |
# specifying a container repoository tag, and updating the service to use the new revision. | |
# | |
# Note: Your application's container MUST be the first container in the task revision. | |
#The tag to deploy. Specify as the first cli argument | |
TAG=$1 | |
# The task name (without the revision number) | |
TASK_FAMILY="hello-world-task" | |
# The service name ( | |
SERVICE_NAME="hello-world" | |
#The image that should be deployed. | |
NEW_DOCKER_IMAGE="1234567890.dkr.ecr.us-east-1.amazonaws.com/hello-world:${TAG}" | |
# The cluster where $SERVICE_NAME | |
CLUSTER_NAME="production" | |
#-------- DO NOT EDIT BELOW THIS LINE --------# | |
OLD_TASK_DEF=$(aws ecs describe-task-definition --task-definition $TASK_FAMILY --output json) | |
NEW_TASK_DEF=$(echo $OLD_TASK_DEF | jq --arg NDI $NEW_DOCKER_IMAGE '.taskDefinition.containerDefinitions[0].image=$NDI') | |
FINAL_TASK=$(echo $NEW_TASK_DEF | jq '.taskDefinition|{family: .family, volumes: .volumes, containerDefinitions: .containerDefinitions}') | |
aws ecs register-task-definition --family ${TASK_FAMILY} --cli-input-json "$(echo $FINAL_TASK)" | |
aws ecs update-service --service $SERVICE_NAME --task-definition $TASK_FAMILY --cluster $CLUSTER_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment