Last active
February 8, 2024 13:19
-
-
Save efrecon/f99172d827b0a9ff7b6dacb41e4723f8 to your computer and use it in GitHub Desktop.
Revisions
-
efrecon revised this gist
May 27, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Docker Tags :no_entry: **[DEPRECATED]** Active as a real [project] instead, development as a gist has been discontinued. [project]: https://github.com/efrecon/reg-tags -
efrecon revised this gist
May 27, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # Docker Tags :no_entry: [DEPRECATED] Active as a real [project] instead, development as a gist has been discontinued. [project]: https://github.com/efrecon/reg-tags -
efrecon renamed this gist
May 27, 2020 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ # Docker Tags **NOTE** This gist has moved to a real [project] instead, development as a gist has been discontinued. [project]: https://github.com/efrecon/reg-tags This "script" implements a single function to list the existing tags at the Docker [hub] for a given public image. -
efrecon revised this gist
May 25, 2020 . 1 changed file with 29 additions and 14 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,17 @@ #!/usr/bin/env sh docker_tags() { _filter=".*" _verbose=0 while [ $# -gt 0 ]; do case "$1" in -f | --filter) _filter=$2; shift 2;; --filter=*) _filter="${1#*=}"; shift 1;; -v | --verbose) _verbose=1; shift;; --) shift; break;; @@ -18,42 +22,53 @@ docker_tags() { esac done # Decide how to download silently download= if command -v curl >/dev/null; then [ "$_verbose" = "1" ] && echo "Using curl for downloads" >&2 # shellcheck disable=SC2037 download="curl -sSL" elif command -v wget >/dev/null; then [ "$_verbose" = "1" ] && echo "Using wget for downloads" >&2 # shellcheck disable=SC2037 download="wget -q -O -" else return 1 fi # Library images or user/org images? if printf %s\\n "$1" | grep -oq '/'; then hub="https://registry.hub.docker.com/v2/repositories/$1/tags/" else hub="https://registry.hub.docker.com/v2/repositories/library/$1/tags/" fi [ "$_verbose" = "1" ] && echo "Discovering pagination from $hub" >&2 # Get number of pages first=$($download "$hub") count=$(printf %s\\n "$first" | sed -E 's/\{\s*"count":\s*([0-9]+).*/\1/') if [ "$count" = "0" ]; then [ "$_verbose" = "1" ] && echo "No tags, probably non-existing repo" >&2 return 0 else [ "$_verbose" = "1" ] && echo "$count existing tag(s) for $1" >&2 fi pagination=$( printf %s\\n "$first" | grep -Eo '"name":\s*"[a-zA-Z0-9_.-]+"' | wc -l) pages=$(( count / pagination + 1)) [ "$_verbose" = "1" ] && echo "$pages pages to download for $1" >&2 # Get all tags one page after the other i=0 while [ "$i" -lt "$pages" ]; do i=$(( i + 1 )) [ "$_verbose" = "1" ] && echo "Downloading page $i / $pages" >&2 page=$($download "$hub?page=$i") printf %s\\n "$page" | grep -Eo '"name":\s*"[a-zA-Z0-9_.-]+"' | sed -E 's/"name":\s*"([a-zA-Z0-9_.-]+)"/\1/' | grep -E "$_filter" done } -
efrecon revised this gist
May 24, 2020 . 1 changed file with 34 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ # Docker Tags This "script" implements a single function to list the existing tags at the Docker [hub] for a given public image. [hub]: https://hub.docker.com/ When called as a script, all arguments will be forwarded to the function so that you will be able to try it. ## Synopsis The function takes short options led by a single-dash, or long options led by a double dash. Long options can be separated from their value by an equal sign or a space separator. Recognised options are: + `-f` or `--filter`, a regular expression to restrict tags to versions matching the expression. ## Example The following will return all tags for the official [alpine] image: ```shell ./docker_tags.sh alpine ``` The following would only return "real" releases for [alpine]: ```shell ./docker_tags.sh --filter '[0-9]+(\.[0-9]+)+' alpine ``` [alpine]: https://hub.docker.com/_/alpine -
efrecon revised this gist
May 24, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -57,6 +57,7 @@ docker_tags() { done } # Run directly? call function! if [ "$(basename "$0")" = "docker_tags.sh" ] && [ "$#" -gt "0" ]; then docker_tags "$@" fi -
efrecon created this gist
May 24, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ #!/usr/bin/env sh docker_tags() { filter=.* while [ $# -gt 0 ]; do case "$1" in -f | --filter) filter=$2; shift 2;; --filter=*) filter="${1#*=}"; shift 1;; --) shift; break;; -*) echo "$1 unknown option!" >&2; return 1;; *) break; esac done if printf %s\\n "$1" | grep -oq '/'; then hub="https://registry.hub.docker.com/v2/repositories/$1/tags/" else hub="https://registry.hub.docker.com/v2/repositories/library/$1/tags/" fi # Get number of pages download= if command -v curl >/dev/null; then # shellcheck disable=SC2037 download="curl -sSL" elif command -v wget >/dev/null; then # shellcheck disable=SC2037 download="wget -q -O -" else return 1 fi first=$($download "$hub") count=$(printf %s\\n "$first" | sed -E 's/\{\s*"count":\s*([0-9]+).*/\1/') [ "$count" = "0" ] && return 0 pagination=$( printf %s\\n "$first" | grep -Eo '"name":\s*"[a-zA-Z0-9_.-]+"' | wc -l) pages=$(( count / pagination + 1)) # Get all tags one page after the other i=0 while [ "$i" -le "$pages" ]; do i=$(( i + 1 )) page=$($download "$hub?page=$i") printf %s\\n "$page" | grep -Eo '"name":\s*"[a-zA-Z0-9_.-]+"' | sed -E 's/"name":\s*"([a-zA-Z0-9_.-]+)"/\1/' | grep -E "$filter" done } if [ "$#" -gt "0" ]; then docker_tags "$@" fi