Skip to content

Instantly share code, notes, and snippets.

@sportebois
Created March 29, 2018 18:55
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save sportebois/1c18011fe74b8932b41c3cc72fbbc174 to your computer and use it in GitHub Desktop.
Save sportebois/1c18011fe74b8932b41c3cc72fbbc174 to your computer and use it in GitHub Desktop.
Add tag to a docker image in ECR via AWS CLI
#!/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}"
}
@mrnim94
Copy link

mrnim94 commented Oct 31, 2023

Thank you so much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment