Last active
June 11, 2022 05:53
-
-
Save nsakki55/47fa76080719b17210c1327a2f17d1a2 to your computer and use it in GitHub Desktop.
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
%%sh | |
# Specify an algorithm name | |
algorithm_name=$1 | |
dockerfiler=$2 | |
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) | |
fullname="${account}.dkr.ecr.${region}.amazonaws.com/${algorithm_name}:latest" | |
echo $fullname | |
# 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-password --region ${region}|docker login --username AWS --password-stdin ${fullname} | |
# Build the docker image locally with the image name and then push it to ECR | |
# with the full name. | |
docker build -t ${algorithm_name} -f ${dockerfiler}/Dockerfile . | |
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