Created
April 11, 2019 04:06
-
-
Save colinjfw/aa967716e8694fd34506edf258b107aa to your computer and use it in GitHub Desktop.
ECS Deployment Script
This file contains 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
#!/bin/bash | |
set -e | |
# Set the variables below or add them dynamically. | |
region="us-west-2" | |
environment="<environment>" | |
cluster="<cluster>" | |
commit=$(git rev-parse --short HEAD) | |
full_commit=$(git rev-parse HEAD) | |
project="<name>" | |
image="<account-id>.dkr.ecr.us-west-2.amazonaws.com/$project:$commit" | |
echo "region: $region" | |
echo "environment: $environment" | |
echo "commit: $commit" | |
echo "cluster: $cluster" | |
echo "project: $project" | |
echo "image: $image" | |
function release() { | |
local service="$1" | |
export AWS_DEFAULT_REGION="$region" | |
# Get the task definition and patch the image value. | |
aws ecs describe-task-definition --task-definition $service \ | |
| jq -r '.taskDefinition' \ | |
| jq -r '{family, containerDefinitions, networkMode, volumes, networkMode, volumes, cpu, memory}' > task-definition.json | |
cat task-definition.json | jq '.containerDefinitions[0].image = "'$image'"' > new-task-definition.json | |
# Register the task definition and get the next revision. | |
revision=$(aws ecs register-task-definition --cli-input-json "$(cat new-task-definition.json)" | jq -r '.taskDefinition.revision') | |
echo -n "deploying $service to $revision..." | |
# Contains secrets. | |
rm task-definition.json | |
rm new-task-definition.json | |
# Patch the service to the next revision. | |
aws ecs update-service --cluster $cluster --service $service --task-definition $service:$revision &> /dev/null | |
echo " done" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment