|
6 | 6 | import subprocess
|
7 | 7 | from contextlib import contextmanager
|
8 | 8 |
|
| 9 | +import backoff |
9 | 10 | from mockbuild.trace_decorator import getLog, traceLog
|
10 | 11 | from mockbuild import util
|
11 | 12 | from mockbuild.exception import BootstrapError
|
@@ -59,18 +60,23 @@ def __init__(self, buildroot, image):
|
59 | 60 |
|
60 | 61 | @traceLog()
|
61 | 62 | def pull_image(self):
|
62 |
| - """ pull the latest image """ |
| 63 | + """ pull the latest image, return True if successful """ |
63 | 64 | logger = getLog()
|
64 | 65 | logger.info("Pulling image: %s", self.image)
|
65 | 66 | cmd = [self.podman_binary, "pull", self.image]
|
66 | 67 | out, exit_status = util.do_with_status(cmd, env=self.buildroot.env,
|
67 | 68 | raiseExc=False, returnOutput=1)
|
68 | 69 | if exit_status:
|
69 | 70 | logger.error(out)
|
| 71 | + return not exit_status |
70 | 72 |
|
71 |
| - if not podman_check_native_image_architecture(self.image, logger): |
72 |
| - raise BootstrapError("Pulled image has invalid architecture") |
73 |
| - |
| 73 | + def retry_image_pull(self, max_time): |
| 74 | + """ Try pulling the image multiple times """ |
| 75 | + @backoff.on_predicate(backoff.expo, lambda x: not x, |
| 76 | + max_time=max_time, jitter=backoff.full_jitter) |
| 77 | + def _keep_trying(): |
| 78 | + return self.pull_image() |
| 79 | + _keep_trying() |
74 | 80 |
|
75 | 81 | @contextmanager
|
76 | 82 | def mounted_image(self):
|
@@ -100,7 +106,12 @@ def mounted_image(self):
|
100 | 106 | @traceLog()
|
101 | 107 | def cp(self, destination, tar_cmd):
|
102 | 108 | """ copy content of container to destination directory """
|
103 |
| - getLog().info("Copy content of container %s to %s", self.image, destination) |
| 109 | + logger = getLog() |
| 110 | + logger.info("Copy content of container %s to %s", self.image, destination) |
| 111 | + |
| 112 | + if not podman_check_native_image_architecture(self.image, logger): |
| 113 | + raise BootstrapError("Pulled image has invalid architecture") |
| 114 | + |
104 | 115 | with self.mounted_image() as mount_path:
|
105 | 116 | # pipe-out the temporary mountpoint with the help of tar utility
|
106 | 117 | cmd_podman = [tar_cmd, "-C", mount_path, "-c", "."]
|
|
0 commit comments