Skip to content

Commit 5e48b23

Browse files
authored
Fetch platform-specific docker image explicitly
1 parent eb075cd commit 5e48b23

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/ci/docker_pull_helper.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
import logging
88
import traceback
9+
import platform
910

1011

1112
class DockerImage:
@@ -43,7 +44,7 @@ def get_images_with_versions(reports_path, required_image, pull=True):
4344

4445
docker_images = []
4546
for image_name in required_image:
46-
docker_image = DockerImage(image_name)
47+
docker_image = image_name if isinstance(image_name, DockerImage) else DockerImage(image_name)
4748
if image_name in images:
4849
docker_image.version = images[image_name]
4950
docker_images.append(docker_image)
@@ -64,6 +65,15 @@ def get_images_with_versions(reports_path, required_image, pull=True):
6465
time.sleep(i * 3)
6566
logging.info("Got exception pulling docker %s", ex)
6667
latest_error = traceback.format_exc()
68+
69+
# TODO (vnemkov): remove once we have a docker proxy set up.
70+
# Upstream uses some sort of proxy that routes plain images to amd64/aarch64 variants,
71+
# here we do the same manually.
72+
machine_arch = {'x86_64': 'amd64'}[platform.machine().lower()]
73+
if not docker_image.version.endswith(machine_arch):
74+
docker_image.version = f'{docker_image.version}-{machine_arch}'
75+
logging.debug('Trying to fetch machine-specific docker image as %s', docker_image)
76+
6777
else:
6878
raise Exception(
6979
f"Cannot pull dockerhub for image docker pull {docker_image} because of {latest_error}"
@@ -74,3 +84,19 @@ def get_images_with_versions(reports_path, required_image, pull=True):
7484

7585
def get_image_with_version(reports_path, image, pull=True):
7686
return get_images_with_versions(reports_path, [image], pull)[0]
87+
88+
def docker_image(name):
89+
s = name.split(':')
90+
return DockerImage(s[0], s[1] if len(s) > 1 else None)
91+
92+
if __name__ == "__main__":
93+
logging.basicConfig(level=logging.DEBUG)
94+
def parse_args():
95+
import argparse
96+
arg_parser = argparse.ArgumentParser()
97+
arg_parser.add_argument('--image', type=docker_image, nargs='+')
98+
arg_parser.add_argument('--pull', type=bool, default=True)
99+
return arg_parser.parse_args()
100+
101+
args = parse_args()
102+
get_images_with_versions('.', args.image, args.pull)

0 commit comments

Comments
 (0)