Skip to content

Instantly share code, notes, and snippets.

@tuliocasagrande
Last active September 20, 2020 14:27
Show Gist options
  • Save tuliocasagrande/c82959c6e682c13421f3e8a207250198 to your computer and use it in GitHub Desktop.
Save tuliocasagrande/c82959c6e682c13421f3e8a207250198 to your computer and use it in GitHub Desktop.
#!/bin/bash
repository_name=awesome-model
image_tag=latest
aws_account_id=$(aws sts get-caller-identity --query Account --output text)
# Get the region defined in the current configuration (default to us-east-1 if none defined)
region=$(aws configure get region)
region=${region:-us-east-1}
repository_uri=$aws_account_id.dkr.ecr.$region.amazonaws.com/$repository_name
# If the repository doesn't exist in ECR, create it.
aws ecr create-repository --repository-name $repository_name --region $region > /dev/null 2>&1
echo -e "\nBuilding local image: $repository_name"
docker build -t $repository_name .
echo -e "\nTagging the image\n$repository_name => $repository_uri:$image_tag"
docker tag $repository_name $repository_uri:$image_tag
echo -e "\nPushing image to repository"
aws ecr get-login-password --region $region | docker login --username AWS --password-stdin $aws_account_id.dkr.ecr.$region.amazonaws.com
docker push $repository_uri:$image_tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment