-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.py
80 lines (59 loc) · 2.77 KB
/
utils.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
79
80
import distutils.cmd
import re
class DeployDockerBasesCommand(distutils.cmd.Command):
""" A command that builds docker bases for the DockerBackend and deploys them to dockerhub.
"""
description = "Build and deploy docker bases for the DockerBackend"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def list_python_versions(self):
from arca import Arca
arca = Arca()
_, pyenv = arca.get_files("https://github.com/pyenv/pyenv.git", "master")
build_for = re.compile(r"^3\.[678]\.[0-9]+$")
for path in sorted((pyenv / "plugins/python-build/share/python-build/").iterdir()):
if path.is_dir():
continue
if build_for.match(path.name):
yield path.name
def run(self):
import requests
import arca
from arca import DockerBackend
backend = DockerBackend()
backend.check_docker_access()
response = requests.get(
"https://hub.docker.com/v2/repositories/arcaoss/arca/tags/",
params={"page_size": 1000}
)
response = response.json()
available_tags = [x["name"] for x in response["results"]]
if arca.__version__ in available_tags:
print("This version was already pushed into the registry.")
base_arca_name, base_arca_tag = backend.get_arca_base()
print(f"Pulled image {base_arca_name}:{base_arca_tag}, might have to build new python versions.")
else:
base_arca_name, base_arca_tag = backend.get_arca_base(pull=False)
print(f"Built image {base_arca_name}:{base_arca_tag}")
if self.verbose:
for x in backend.client.images.push(base_arca_name, tag=base_arca_tag, stream=True):
print(x.decode("utf-8"), end="")
else:
backend.client.images.push(base_arca_name, tag=base_arca_tag)
print(f"Pushed image {base_arca_name}:{base_arca_tag}")
for python_version in self.list_python_versions():
tag = backend.get_python_base_tag(python_version)
if tag in available_tags:
print(f"Skipping Python version {python_version}, already built for this version of arca.")
continue
image_name, image_tag = backend.get_python_base(python_version, pull=False)
print(f"Built image {image_name}:{image_tag}")
if self.verbose:
for x in backend.client.images.push(image_name, tag=image_tag, stream=True):
print(x.decode("utf-8"), end="")
else:
backend.client.images.push(image_name, tag=image_tag)
print(f"Pushed image {image_name}:{image_tag}")