-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.py
executable file
·70 lines (50 loc) · 2.11 KB
/
upgrade.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# Upgrades all charts to highest available semver-compatible versions
from os import path
from urllib.parse import urlparse
from yaml import load, dump
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
import glob
import dxf
import semver
CHART_DIRECTORIES = "charts/*"
for dir in glob.glob(CHART_DIRECTORIES):
if path.exists(path.join(dir, "Chart.yaml")) and path.exists(path.join(dir, "values.yaml")):
with open(path.join(dir, "values.yaml"), "r") as f:
values = load(f, Loader)
if "image" not in values or "repository" not in values["image"]:
continue
image = values["image"]["repository"]
with open(path.join(dir, "Chart.yaml"), "r") as f:
chart = load(f, Loader)
chartVersion = chart["version"]
appVersion = chart["appVersion"]
print(dir, chartVersion, image, appVersion)
if "/" not in image:
image = "library/" + image
if image.count("/") == 1:
image = "index.docker.io/" + image
url = urlparse("https://" + image)
try:
dxf_obj = dxf.DXF(url.netloc, url.path[1:])
dxf_obj.authenticate(actions=['pull'])
aliases = dxf_obj.list_aliases()
highestSemver = appVersion
for alias in aliases:
if semver.VersionInfo.is_valid(alias):
if semver.compare(highestSemver, alias) == -1:
highestSemver = alias
if appVersion == highestSemver:
print(appVersion, "==", highestSemver, "skipping")
continue
print(appVersion, "<", highestSemver, "upgrading")
chart["appVersion"] = highestSemver
chart["version"] = str(semver.VersionInfo.parse(chartVersion).bump_patch())
with open(path.join(dir, "Chart.yaml"), "w") as f:
dump(chart, f, Dumper)
except Exception as err:
print(err)
print("error, skipping")