diff options
author | Radostin Stoyanov <rstoyanov1@gmail.com> | 2017-07-04 16:24:20 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cbosdonnat@suse.com> | 2017-07-05 09:54:51 +0200 |
commit | 64ef61bd999ab669dcb21424528894f8fad97e0f (patch) | |
tree | 490836f3c8b00efa67c521c6c21f8f689642da91 | |
parent | 04dfccb8acda9d79a3a7dccb16a5670fb3f279e7 (diff) | |
download | virt-bootstrap.git-64ef61bd999ab669dcb21424528894f8fad97e0f.tar.gz virt-bootstrap.git-64ef61bd999ab669dcb21424528894f8fad97e0f.tar.xz virt-bootstrap.git-64ef61bd999ab669dcb21424528894f8fad97e0f.zip |
DockerSource: Use downloaded layers
Do not call "skopeo copy" if layers were downloaded and have valid
hash sum.
Although, "skopeo copy" already does such check for us this change
allow us to control the output and avoids spawning a binary.
-rw-r--r-- | src/virtBootstrap/sources.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py index 78f6be3..9d675cb 100644 --- a/src/virtBootstrap/sources.py +++ b/src/virtBootstrap/sources.py @@ -360,6 +360,28 @@ class DockerSource(object): # Remove the manifest file as it is not needed os.remove(os.path.join(self.images_dir, "manifest.json")) + def validate_image_layers(self): + """ + Check if layers of container image exist in image_dir + and have valid hash sum. + """ + for sum_type, sum_expected, path, _ignore in self.layers: + logger.debug("Checking layer: %s", path) + if not (os.path.exists(path) + and checksum(path, sum_type, sum_expected)): + return False + return True + + def fetch_layers(self): + """ + Retrieve layers of container image. + """ + # Check if layers have been downloaded + if self.validate_image_layers(): + logger.info("Using cached image layers") + else: + self.download_image() + def unpack(self, dest): """ Extract image files from Docker image @@ -370,7 +392,7 @@ class DockerSource(object): # Layers are in order - root layer first # Reference: # https://github.com/containers/image/blob/master/image/oci.go#L100 - self.download_image() + self.fetch_layers() # Unpack to destination directory if self.output_format == 'dir': |