Skip to content

Instantly share code, notes, and snippets.

Created June 20, 2017 00:17

Revisions

  1. @invalid-email-address Anonymous created this gist Jun 20, 2017.
    30 changes: 30 additions & 0 deletions stdlib.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    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
    }