Created
March 29, 2018 18:55
-
-
Save sportebois/1c18011fe74b8932b41c3cc72fbbc174 to your computer and use it in GitHub Desktop.
Add tag to a docker image in ECR via AWS CLI
This file contains hidden or 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
#!/usr/bin/env bash | |
function ecr-add-tag() { | |
if (( $# < 3 )); then | |
echo "Wrong number of arguments. Usage: ecr-add-tag ECR_REPO_NAME TAG_TO_FIND TAG_TO_ADD [AWS_PROFILE]" | |
return | |
fi | |
local repo_name=$1 | |
local existing_tag=$2 | |
local new_tag=$3 | |
local profile=$4 | |
[[ ! -z "$profile" ]] && profile="--profile ${profile}" | |
manifest=`aws ecr batch-get-image ${profile} \ | |
--repository-name $repo_name \ | |
--image-ids imageTag=$existing_tag \ | |
--query 'images[].imageManifest' \ | |
--output text` | |
aws ecr put-image ${profile} \ | |
--repository-name $repo_name \ | |
--image-tag $new_tag \ | |
--image-manifest "${manifest}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much