Skip to content

Instantly share code, notes, and snippets.

@asvinours
Created April 15, 2018 15:21
Show Gist options
  • Save asvinours/cc02f56735f3e731ac25ec778a98085f to your computer and use it in GitHub Desktop.
Save asvinours/cc02f56735f3e731ac25ec778a98085f to your computer and use it in GitHub Desktop.
build and push to ECR
# The name of our algorithm
algorithm_name=rmars
#set -e # stop if anything fails
account=$(aws sts get-caller-identity --query Account --output text)
# Get the region defined in the current configuration (default to us-west-2 if none defined)
region=$(aws configure get region)
region=${region:-us-west-2}
fullname="${account}.dkr.ecr.${region}.amazonaws.com/${algorithm_name}:latest"
# If the repository doesn't exist in ECR, create it.
aws ecr describe-repositories --repository-names "${algorithm_name}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
aws ecr create-repository --repository-name "${algorithm_name}" > /dev/null
fi
# Get the login command from ECR and execute it directly
$(aws ecr get-login --region ${region} --no-include-email)
# Build the docker image locally with the image name and then push it to ECR
# with the full name.
docker build -t ${algorithm_name} .
docker tag ${algorithm_name} ${fullname}
docker push ${fullname}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment