Skip to content

Instantly share code, notes, and snippets.

@behconsci
Created January 16, 2018 14:27
Show Gist options
  • Save behconsci/67dc1734ceebf8d64eadf30418899e91 to your computer and use it in GitHub Desktop.
Save behconsci/67dc1734ceebf8d64eadf30418899e91 to your computer and use it in GitHub Desktop.
replace the AWS_ACCOUNT_ID with aws-account-id
#!/bin/sh
git_commit_hash=$1
echo "get new login token ... "
$(aws ecr get-login --region eu-central-1 --no-include-email)
. stop_local.sh
docker images | gawk '{ printf $1" "}; {printf $3" "}; {printf "\n"}; ' > dotmp 2> dotmp
old_image_id=`cat dotmp | gawk '$1 ~ AWS_ACCOUNT_ID { printf $2"\n" }; ' | grep -m1 ""`
docker rmi -f $old_image_id
. start_local.sh
docker images | gawk '{ printf $1" "}; {printf $3" "}; {printf "\n"}; ' > dotmp 2> dotmp
new_image_id=`cat dotmp | gawk '$1 ~ AWS_ACCOUNT_ID { printf $2"\n" }; ' | grep -m1 ""`
docker tag $new_image_id AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com/yourapp/python-base:latest
docker tag $new_image_id AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com/yourapp/python-base:$git_commit_hash
docker push AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com/yourapp/python-base:latest
docker push AWS_ACCOUNT_ID.dkr.ecr.eu-central-1.amazonaws.com/yourapp/python-base:$git_commit_hash
echo "NEW IMAGE IS PUSHED TO AWS ECS"
@behconsci
Copy link
Author

start_local.sh is your shell script to build your docker image
stop_local.sh is your shell script to stop running containers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment