-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_latest_tag.py
50 lines (39 loc) · 1.15 KB
/
get_latest_tag.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
# arkadiko
# https://github.com/topfreegames/arkadiko
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright © 2016 Top Free Games <backend@tfgco.com>
import urllib
import urllib2
import json
def main():
url = "https://auth.docker.io/token?service=registry.docker.io&scope=repository:tfgco/arkadiko:pull,push"
response = urllib.urlopen(url)
token = json.loads(response.read())['token']
url = "https://registry-1.docker.io/v2/tfgco/arkadiko/tags/list"
req = urllib2.Request(url, None, {
"Authorization": "Bearer %s" % token,
})
response = urllib2.urlopen(req)
tags = json.loads(response.read())
last_tag = get_last_tag(tags['tags'])
print last_tag
def get_tag_value(tag):
while len(tag) < 4:
tag.append('0')
total_value = 0
for index, tag_part in enumerate(tag):
power = pow(100, len(tag) - index)
total_value += int(tag_part) * power
return total_value
def get_last_tag(tags):
return '.'.join(
max([
(get_tag_value(tag), tag) for tag in
[t.split('.') for t in tags]
], key=lambda i: i[0]
)[1]
)
if __name__ == "__main__":
main()