Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vincentclaes/f587ba84bf116ed39d2841e49387f6c5 to your computer and use it in GitHub Desktop.
Save vincentclaes/f587ba84bf116ed39d2841e49387f6c5 to your computer and use it in GitHub Desktop.
script to build docker image and push the image to aws ecr
# The name of our algorithm
export AWS_PROFILE= # your AWS profile
algorithm_name= # name of your algorithm
region= # aws region e.g. eu-central-1
account=$(aws sts get-caller-identity --query Account --output text)
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