From a223b15938237665fe135cd710f4301ea23bf85d Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Fri, 15 Dec 2017 23:05:33 +0000 Subject: docker-source: Get list of layers without `--raw` When `skopeo inspect --raw docker://feodra` is used the returned manifest content contains a list with manifests for specific platforms [1] rather than a list with layers. By using `skopeo inpect docker://fedora` the correct manifest content is retrieved and a list with layers is provided. In addition, skopeo handles the difference between schemaVersion 1 and 2. [1] https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list-field-descriptions --- src/virtBootstrap/sources/docker_source.py | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/virtBootstrap/sources/docker_source.py b/src/virtBootstrap/sources/docker_source.py index ec1a812..0eace81 100644 --- a/src/virtBootstrap/sources/docker_source.py +++ b/src/virtBootstrap/sources/docker_source.py @@ -77,7 +77,7 @@ class DockerSource(object): self.no_cache = kwargs.get('no_cache', False) self.progress = kwargs['progress'].update_progress self.images_dir = utils.get_image_dir(self.no_cache) - self.manifest = None + self.image_details = None self.layers = [] self.checksums = [] @@ -91,30 +91,25 @@ class DockerSource(object): Retrive manifest from registry and get layers' digest, sum_type, size and file_path in a list. """ - self.manifest = utils.get_image_details(self.url, raw=True, + image_details = utils.get_image_details(self.url, raw=False, insecure=self.insecure, username=self.username, password=self.password) - if self.manifest['schemaVersion'] == 1: - layers_list = self.manifest['fsLayers'][::-1] - digest_field = 'blobSum' - elif self.manifest['schemaVersion'] == 2: - layers_list = self.manifest['layers'] - digest_field = 'digest' - else: - raise ValueError('Unsupported manifest schema.') + if not 'Layers' in image_details or not image_details['Layers']: + raise ValueError('No image layers.') - for layer in layers_list: - # Store checksums of layers - layer_digest = layer[digest_field] + # Layers are in order: + # - root layer first, and then successive layered layers + # Ref: https://github.com/containers/image/blob/master/image/oci.go + for layer_digest in image_details['Layers']: sum_type, layer_sum = layer_digest.split(':') - self.checksums.append([sum_type, layer_sum]) + self.checksums.append([sum_type, layer_sum]) # Store checksums - # Store file path and size of each layer + # Layers are tar files with hashsum used as name file_path = os.path.join(self.images_dir, layer_sum + '.tar') - layer_size = layer.get('size', None) - self.layers.append([file_path, layer_size]) + # Store 'file path' and set placeholder for 'size' + self.layers.append([file_path, None]) def gen_valid_uri(self, uri): """ -- cgit