Skip to content

Instantly share code, notes, and snippets.

@philwinder
Created January 10, 2017 15:38
Show Gist options
  • Save philwinder/8222eeb05bad16a13a2646ebf033e12f to your computer and use it in GitHub Desktop.
Save philwinder/8222eeb05bad16a13a2646ebf033e12f to your computer and use it in GitHub Desktop.
Tests V1 and V2 apis to get container tags from docker hub api
#!/bin/bash
# Tests V1 and V2 API for getting tags. The V1 api is garbage, but the V2 api isn't fully implemented.
# -------
set -e
echo
echo ""
echo "Testing V2 api"
V2_TOKEN=$(curl -s -H "Content-Type: application/json" -X GET 'https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/node:pull' | jq -r .token)
echo "= Token ${V2_TOKEN}"
curl -s -H "Authorization: Bearer ${V2_TOKEN}" 'https://registry-1.docker.io/v2/library/node/tags/list?n=1' -w %{time_connect}:%{time_starttransfer}:%{time_total}
echo ""
echo "Testing V1 API"
V1_ENDPOINT=$(curl -si https://registry.hub.docker.com/v1/repositories/library/node/images -H 'X-Docker-Token: true' | grep X-Docker-Endpoints | cut -d " " -f2- | tr -d '[:space:]')
echo "= Endpoint ${V1_ENDPOINT}"
V1_TOKEN=$(curl -si https://registry.hub.docker.com/v1/repositories/library/node/images -H 'X-Docker-Token: true' | grep X-Docker-Token | cut -d " " -f2- | tr -d '[:space:]')
echo "= Token ${V1_TOKEN}"
echo "= Getting tags from https://${V1_ENDPOINT}/v1/repositories/library/node/tags, this might take a while"
time curl https://${V1_ENDPOINT}/v1/repositories/library/node/tags?n=1 -H "Authorization: Token ${V1_TOKEN}"
echo ""
echo "Testing another V1 API"
echo "# omg: this often fails and returns an 'oops there was an error' message. Probably because it's taking too long."
echo "# I have seen it work sometimes though."
time curl https://registry.hub.docker.com/v1/repositories/node/tags || true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment