Skip to content

Instantly share code, notes, and snippets.

@meet59patel
Last active March 30, 2020 20:37
Show Gist options
  • Save meet59patel/a8c2d86ea1f92253ff5ad060fb657fc8 to your computer and use it in GitHub Desktop.
Save meet59patel/a8c2d86ea1f92253ff5ad060fb657fc8 to your computer and use it in GitHub Desktop.
Search Docker Tags

This script uses DockerHub registry API v2, which returns JSON response of tags in paginated manner. So the script...

  1. Fetches the response (using curl)
  2. Takes out all the versions returned on a single page (using python)
  3. Goes to the next page, repeats steps 1 and 2
  4. Makes a list at every iteration and prints it out at the end.
#!/bin/bash
# Initial URL
url=https://registry.hub.docker.com/v2/repositories/percona/pmm-server/tags/
(
# Keep looping until the variable URL is empty
while [ ! -z $url ]; do
# Every iteration of the loop prints out a single dot to show progress as it got through all the pages (this is inline dot)
>&2 echo -n "."
# Curl the URL and pipe the output to Python. Python will parse the JSON and print the very first line as the next URL (it will leave it blank if there are no more pages)
# then continue to loop over the results extracting only the name; all will be stored in a variable called content
content=$(curl -s $url | python -c 'import sys, json; data = json.load(sys.stdin); print(data.get("next", "") or ""); print("\n".join([x["name"] for x in data["results"]]))')
# Let's get the first line of content which contains the next URL for the loop to continue
url=$(echo "$content" | head -n 1)
# Print the content without the first line (yes +2 is counter intuitive)
echo "$content" | tail -n +2
done;
# Finally break the line of dots
>&2 echo
) | cut -d '-' -f 1 | sort --version-sort | uniq;
meet@meet-VirtualBox:~/Documents/temp$ ./tag-checkr.sh
.......
1
1.0.0
1.0.1
1.0.2
1.0.3
1.0.4
1.0.5
1.0.6
1.0.7
1.1.1
1.1.2
1.1.3
1.1.4
1.1.5
1.2.0
1.2.1
1.2.2
1.3.0
1.3.1
1.3.2
1.4.0
1.4.1
1.5.0
1.5.1
1.5.2
1.5.3
1.6.0
1.6.1
1.7.0
1.8.0
1.8.1
1.9.0
1.9.1
1.10.0
1.11.0
1.12.0
1.13.0
1.14.0
1.14.1
1.15.0
1.16.0
1.17
1.17.0
1.17.1
1.17.2
1.17.3
2
2.0
2.0.0
2.0.1
2.1
2.1.0
2.2
2.2.0
2.2.1
2.2.2
2.3
2.3.0
2.4
2.4.0
latest
meet@meet-VirtualBox:~/Documents/temp$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment