Created
June 20, 2017 06:15
-
-
Save anonymous/36a7e8b70769fb87c0d037ff01fb4e91 to your computer and use it in GitHub Desktop.
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
aws_ecr_curl() { | |
login_cmd=$(aws ecr get-login) | |
username=$(echo "$login_cmd" | cut -d " " -f 4) | |
password=$(echo "$login_cmd" | cut -d " " -f 6) | |
endpoint=$(echo "$login_cmd" | cut -d " " -f 9) | |
args=("$@") | |
args_length=${#args[@]} | |
args_last=${args[$args_length-1]} | |
unset 'args[${args_length}-1]' | |
path="${args_last}" | |
curl \ | |
-u "${username}:${password}" \ | |
"${args[@]}" \ | |
"${endpoint}${path}" | |
} | |
# Usage: docker_tag_exists somerepo sometag | |
docker_tag_exists() { | |
repo_name="$1" | |
tag="$2" | |
aws_ecr_curl \ | |
--head \ | |
--fail \ | |
-s \ | |
"/v2/${repo_name}/manifests/${tag}" \ | |
> /dev/null | |
} | |
docker_image_exists() { | |
image="$1" | |
repo_name_with_tag=$(echo "$image" | cut -d "/" -f 2) | |
repo_name=$(echo "$repo_name_with_tag" | cut -d ":" -f 1) | |
tag=$(echo "$repo_name_with_tag" | cut -d ":" -f 2) | |
docker_tag_exists "${repo_name}" "${tag}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment