-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrebuild.py
executable file
·78 lines (60 loc) · 2.09 KB
/
rebuild.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
71
72
73
74
75
76
77
78
#!/usr/bin/python3
import urllib.request
import json
import tempfile
import subprocess
from pathlib import Path
VARIANTS = [
'',
'slim',
'alpine'
]
def get_json(url):
with urllib.request.urlopen(url) as resp:
return json.load(resp)
def build_dockerfile(fobj, *, which='xonsh', variant=None, version=None):
"""
Write out a Dockerfile for the given variant and xonsh version.
Variant should match one of the python container tag suffixes (eg slim, alpine)
"""
fobj.write(Path(f"templates/Dockerfile.{which}").read_text().format(
dashvariant=f"-{variant}" if variant else "",
colonvariant=f":{variant}" if variant else "",
specifier=f"=={version}" if version else ""
))
def rebuild_branch(which, version, variant, *, unversioned=False):
if variant:
tags = [f"xonsh/{which}:{version}-{variant}"]
else:
tags = [f"xonsh/{which}:{version}"]
if unversioned:
if variant:
tags += [f"xonsh/{which}:{variant}"]
else:
tags += [f"xonsh/{which}:latest"]
print(f"== Building {which} {version} {variant} ==", flush=True)
with tempfile.TemporaryFile(mode='w+t', encoding='utf-8') as ntf:
build_dockerfile(ntf, which=which, version=version, variant=variant)
ntf.flush()
ntf.seek(0)
subprocess.run(
["docker", "build", *(f"--tag={t}" for t in tags), "-f-", "."],
stdin=ntf, check=True,
)
for t in tags:
print(f"== Pushing {t} ==", flush=True)
subprocess.run(
["docker", "push", t],
check=True,
)
metadata = get_json("https://pypi.org/pypi/xonsh/json")
latest = metadata['info']['version']
# Do this to publish all versions
# versions = metadata['releases'].keys()
# for version in versions:
# for variant in VARIANTS:
# rebuild_branch(version, variant, unversioned=(version == latest))
for container in ('xonsh', 'action', 'interactive'):
for variant in VARIANTS:
rebuild_branch(container, latest, variant, unversioned=True)
print("", flush=True)