Created
November 30, 2016 14:31
-
-
Save Johnz86/c97f469592639d49bfa740fd594dd510 to your computer and use it in GitHub Desktop.
Deploy image to aws and restart the task and service to redeploy new container.
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 | |
awsRegion=eu-west-1 | |
containerName=imagepool_web | |
containerRepository=126375660691.dkr.ecr.eu-west-1.amazonaws.com/image-pool | |
version=0.1 | |
increment_version (){ | |
declare -a part=( ${1//\./ } ) | |
declare new | |
declare -i carry=1 | |
for (( CNTR=${#part[@]}-1; CNTR>=0; CNTR-=1 )); do | |
len=${#part[CNTR]} | |
new=$((part[CNTR]+carry)) | |
[ ${#new} -gt $len ] && carry=1 || carry=0 | |
[ $CNTR -gt 0 ] && part[CNTR]=${new: -len} || part[CNTR]=${new} | |
done | |
new="${part[*]}" | |
echo -e "${new// /.}" | |
} | |
#if docker image version does exist in repository increment existing version by one | |
loaded_version=`aws ecr list-images --repository-name image-pool --filter 'tagStatus=TAGGED' --query 'imageIds[].[imageTag][-1]' --output=text --profile build` | |
if [ ! -z "${loaded_version##*[!0-9.]*}" ]; then | |
version=$(increment_version $loaded_version) | |
fi | |
echo "build latest version $containerRepository:$version" | |
cd $(dirname $(dirname $(readlink -f $0))) | |
echo "build production docker image..." | |
docker-compose -f docker-compose.production.yml build | |
echo "docker login to aws..." | |
eval $(aws ecr get-login --region eu-west-1 --profile build) | |
echo "tag $containerName:latest" | |
docker tag $containerName:latest $containerRepository:latest | |
docker tag $containerRepository:latest $containerRepository:$version | |
echo "push docker image version $version" | |
docker push $containerRepository:$version | |
docker push $containerRepository:latest | |
echo 'update task definition...' | |
aws ecs register-task-definition --cli-input-json file://tasks/register-dev-imagepool.json --region eu-west-1 --profile build | |
echo 'update our service with that last task..' | |
aws ecs update-service --cluster dev-imagepool --service imagepool-service --task-definition dev-imagepool --desired-count 1 --profile build |
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
{ | |
"family": "dev-imagepool", | |
"networkMode": "bridge", | |
"containerDefinitions": [ | |
{ | |
"memory": 512, | |
"portMappings": [ | |
{ | |
"hostPort": 27017, | |
"containerPort": 27017, | |
"protocol": "tcp" | |
} | |
], | |
"essential": true, | |
"name": "db", | |
"image": "mongo:latest", | |
"cpu": 0, | |
"memoryReservation": 256 | |
}, | |
{ | |
"memory": 512, | |
"portMappings": [ | |
{ | |
"hostPort": 8000, | |
"containerPort": 8000, | |
"protocol": "tcp" | |
} | |
], | |
"essential": true, | |
"name": "web", | |
"environment": [ | |
{ | |
"name": "MONGO_URL", | |
"value": "mongodb://db:27017/mern-starter" | |
}, | |
{ | |
"name": "NODE_ENV", | |
"value": "production" | |
} | |
], | |
"links": [ | |
"db" | |
], | |
"image": "126375660691.dkr.ecr.eu-west-1.amazonaws.com/image-pool:latest", | |
"cpu": 0, | |
"memoryReservation": 256 | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment