Skip to content

Instantly share code, notes, and snippets.

@BrunIF
Forked from sportebois/ecr-add-tag.sh
Created April 10, 2020 07:06
Show Gist options
  • Save BrunIF/b1f570196c805a020fc5fc03f7a48163 to your computer and use it in GitHub Desktop.
Save BrunIF/b1f570196c805a020fc5fc03f7a48163 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}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment