-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-tags.py
executable file
·37 lines (33 loc) · 1.07 KB
/
docker-tags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python
import json
import urllib2
import sys
def get_tags( image):
tmp = image.split("/")
if len( tmp ) == 3:
f = urllib2.urlopen("https://%s/v2/%s/tags/list" % (tmp[0], "/".join( tmp[1:] ) ) )
else:
fetch = False
try:
f = urllib2.urlopen("https://registry.hub.docker.com/v1/repositories/%s/tags" % image )
fetch = True
except Exception as ex:
pass
if not fetch:
print "https://%s/v2/%s/tags/list" % (tmp[0], "/".join( tmp[1:] ) )
f = urllib2.urlopen("https://%s/v2/%s/tags/list" % (tmp[0], "/".join( tmp[1:] ) ) )
try:
jsonData = json.loads( f.read() )
tags = []
if type(jsonData) is list:
for data in jsonData:
tags.append( data["name"] )
elif "tags" in jsonData:
for data in jsonData["tags"]:
tags.append( data )
tags = sorted( tags )
print "\n".join( tags )
except:
print "not find %s" % image
if __name__ == "__main__":
get_tags( sys.argv[1] )