From 64ef61bd999ab669dcb21424528894f8fad97e0f Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Tue, 4 Jul 2017 16:24:20 +0100 Subject: 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. --- src/virtBootstrap/sources.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/virtBootstrap/sources.py') 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': -- cgit