[virt-tools-list] [virt-bootstrap] [PATCH v3 03/12] DockerSource: Add support for Manifest version 1
Radostin Stoyanov
rstoyanov1 at gmail.com
Thu Jul 20 11:29:38 UTC 2017
Handle differences between version 1 and 2 of the Manifest file for
Docker registry.
Layers' blob sums in v1 are stored in a list "fsLayers" and the digest
is stored in following filed with name "blobSum". [1]
In v2 the layer list is stored in field with name "layers" and
ordered starting from the base image (opposite order of v1). The digest
is stored under a following field with name "digest". The size in bytes
is included in a field with name "size". [2]
[1] https://docs.docker.com/registry/spec/manifest-v2-1/#manifest-field-descriptions
[2] https://docs.docker.com/registry/spec/manifest-v2-2/#image-manifest-field-descriptions
---
src/virtBootstrap/sources.py | 18 +++++++++++++++---
src/virtBootstrap/utils.py | 7 +++++--
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py
index 4f1b104..1e70f33 100644
--- a/src/virtBootstrap/sources.py
+++ b/src/virtBootstrap/sources.py
@@ -128,10 +128,22 @@ class DockerSource(object):
username=self.username,
password=self.password)
- for layer in self.manifest['layers']:
- sum_type, layer_sum = layer['digest'].split(':')
+ if self.manifest['schemaVersion'] == 1:
+ layers_list = self.manifest['fsLayers'][::-1]
+ digest_filed = 'blobSum'
+ elif self.manifest['schemaVersion'] == 2:
+ layers_list = self.manifest['layers']
+ digest_filed = 'digest'
+ else:
+ raise ValueError('Unsupported manifest schema.')
+
+ for layer in layers_list:
+ layer_digest = layer[digest_filed]
+ layer_size = layer['size'] if 'size' in layer else None
+
+ sum_type, layer_sum = layer_digest.split(':')
file_path = os.path.join(self.images_dir, layer_sum + '.tar')
- self.layers.append([sum_type, layer_sum, file_path, layer['size']])
+ self.layers.append([sum_type, layer_sum, file_path, layer_size])
def gen_valid_uri(self, uri):
"""
diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
index daabd26..a65d3f5 100644
--- a/src/virtBootstrap/utils.py
+++ b/src/virtBootstrap/utils.py
@@ -138,8 +138,11 @@ def log_layer_extract(layer, current, total, progress):
Create log message on layer extract.
"""
sum_type, sum_value, layer_file, layer_size = layer
- progress("Extracting layer (%s/%s) with size: %s"
- % (current, total, bytes_to_size(layer_size)), logger=logger)
+ msg = 'Extracting layer (%s/%s)' % (current, total)
+
+ if layer_size:
+ msg += " with size: %s" % bytes_to_size(layer_size)
+ progress(msg, logger=logger)
logger.debug('Untar layer: (%s:%s) %s', sum_type, sum_value, layer_file)
--
2.9.4
More information about the virt-tools-list
mailing list