def _get_manifest_list(self, image: ImageName) -> requests.Response: """try to figure out manifest list""" if image in self.manifest_list_cache: return self.manifest_list_cache[image] reg_client = self._get_registry_client(image.registry) manifest_list = reg_client.get_manifest_list(image) if '@sha256:' in str(image) and not manifest_list: # we want to adjust the tag only for manifest list fetching image = image.copy() try: config_blob = reg_client.get_config_from_registry( image, image.tag) except (HTTPError, RetryError, Timeout) as ex: self.log.warning('Unable to fetch config for %s, got error %s', image, ex.response.status_code) raise RuntimeError( 'Unable to fetch config for base image') from ex release = config_blob['config']['Labels']['release'] version = config_blob['config']['Labels']['version'] docker_tag = "%s-%s" % (version, release) image.tag = docker_tag manifest_list = reg_client.get_manifest_list(image) self.manifest_list_cache[image] = manifest_list return self.manifest_list_cache[image]
def _store_manifest_digest(self, image: ImageName, use_original_tag: bool) -> None: """Store media type and digest for manifest list or v2 schema 2 manifest digest""" image_str = image.to_str() manifest_list = self._get_manifest_list(image) reg_client = self._get_registry_client(image.registry) if manifest_list: digest_dict = get_checksums(BytesIO(manifest_list.content), ['sha256']) media_type = get_manifest_media_type('v2_list') else: digests_dict = reg_client.get_all_manifests(image, versions=('v2',)) media_type = get_manifest_media_type('v2') try: manifest_digest_response = digests_dict['v2'] except KeyError as exc: raise RuntimeError( 'Unable to fetch manifest list or ' 'v2 schema 2 digest for {} (Does image exist?)'.format(image_str) ) from exc digest_dict = get_checksums(BytesIO(manifest_digest_response.content), ['sha256']) manifest_digest = 'sha256:{}'.format(digest_dict['sha256sum']) parent_digests = {media_type: manifest_digest} if use_original_tag: # image tag may have been replaced with a ref for autorebuild; use original tag # to simplify fetching parent_images_digests data in other plugins image = image.copy() base_image_key: ImageName = self.workflow.data.dockerfile_images.base_image_key image.tag = base_image_key.tag image_str = image.to_str() self.workflow.data.parent_images_digests[image_str] = parent_digests