builder: fetch manifests for the compose

Add support for fetching manifests via the compose/<id>/manifests
API endpoint. A failure to fetch them is not critical, since it is
possible the manifests don't exist, e.g. when depsolving fails.
The manifest is attached per image request.
This commit is contained in:
Christian Kellner 2021-02-25 14:28:41 +01:00
parent db6d4645df
commit efc648f32a

View file

@ -246,6 +246,18 @@ class Client:
return ComposeLogs.from_dict(res.json())
def compose_manifests(self, compose_id: str):
url = urllib.parse.urljoin(self.url, f"compose/{compose_id}/manifests")
res = self.http.get(url)
if res.status_code != 200:
body = res.content.decode("utf-8").strip()
msg = f"Failed to get the compose manifests: {body}"
raise koji.GenericError(msg) from None
return res.json()
def wait_for_compose(self, compose_id: str, *, sleep_time=2, callback=None):
while True:
status = self.compose_status(compose_id)
@ -330,6 +342,21 @@ class OSBuildImage(BaseTaskHandler):
self.logger.debug("Uploading logs: %s", name)
self.upload_json(log, name)
def attach_manifests(self, compose_id: str, ireqs: ImageRequest):
self.logger.debug("Fetching manifests")
try:
manifests = self.client.compose_manifests(compose_id)
except koji.GenericError as e:
self.logger.warning("Failed to fetch manifests: %s", str(e))
return
imanifests = zip(manifests, ireqs)
for manifest, ireq in imanifests:
name = "%s-%s.manifest" % (ireq.architecture, ireq.image_type)
self.logger.debug("Uploading manifest: %s", name)
self.upload_json(manifest, name)
@staticmethod
def arches_for_config(buildconfig: Dict):
archstr = buildconfig["arches"]
@ -427,6 +454,7 @@ class OSBuildImage(BaseTaskHandler):
self.logger.debug("Compose finished: %s", str(status.as_dict()))
self.logger.info("Compose result: %s", status.status)
self.attach_manifests(cid, ireqs)
self.attach_logs(cid, ireqs)
if not status.is_success: