Created
October 4, 2020 14:22
-
-
Save spacelatte/84977967d906ce06ca44bfbe658d03d2 to your computer and use it in GitHub Desktop.
#docker #hub #registry #pull #manifest #touch images to keep retention period of those from docker-hub's new policy ...
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 -S bash -xo pipefail | |
users=( "$@" ) | |
baseurl="https://registry.hub.docker.com/v2" | |
#baseurl="https://registry-1.docker.io/v2" | |
function get_token { | |
local user="${1}" | |
local repo="${2}" | |
local scope="repository:${user}/${repo}:pull" | |
local service="registry.docker.io" | |
curl -sf \ | |
"https://auth.docker.io/token?service=${service}&scope=${scope}" \ | |
| jq -r .token | |
return | |
} | |
function fetch_user { | |
curl -sfL \ | |
-H 'User-Agent: Docker-Client/19.03.12' \ | |
"${baseurl}/repositories/${user}/?page_size=999" \ | |
| jq -r '.results | .[] | .name' | |
#| jq -r '.results | .[] | (.user + "/" + .name)' | |
return | |
} | |
function fetch_tags { | |
local user="${1}" | |
local repo="${2}" | |
# local url="${baseurl}/repositories/${repo}/tags/" \ | |
# works with registry.hub.docker.com | |
local url="${baseurl}/${user}/${repo}/tags/list" | |
curl -sfL \ | |
-H 'User-Agent: Docker-Client/19.03.12' \ | |
-H "Authorization: Bearer $( get_token "${user}" "${repo}" )" \ | |
"${url}" | jq -r '.tags | .[]' | |
return | |
} | |
function fetch_manifests { | |
local user="${1}" | |
local repo="${2}" | |
local tag="${3}" | |
local url="${baseurl}/${user}/${repo}/manifests/${tag}" | |
curl -sfL \ | |
-H 'User-Agent: Docker-Client/19.03.12' \ | |
-H "Authorization: Bearer $( get_token "${user}" "${repo}" )" \ | |
"${url}" \ | |
| jq -r '(.name + ":" + .["tag"] + ":" + .architecture)' | |
return | |
} | |
# export baseurl | |
# export -f get_token | |
# export -f fetch_tags | |
# export -f fetch_user | |
# export -f fetch_manifests | |
for user in "${users[@]}"; do | |
for repo in $( fetch_user "${user}" ); do | |
for tag in $( fetch_tags "${user}" "${repo}" ); do | |
fetch_manifests "${user}" "${repo}" "${tag}" & | |
done # & wait -f | |
done # & wait -f | |
done # & wait -f | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment