summaryrefslogtreecommitdiffstats
path: root/src/virtBootstrap/sources.py
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-04 13:46:43 +0100
committerCédric Bosdonnat <cbosdonnat@suse.com>2017-07-04 16:18:39 +0200
commit78a5313c1076580c4a7308294765c26caa2da127 (patch)
tree31e84341703f0c81e7a61c5d7bac33b063dd2542 /src/virtBootstrap/sources.py
parent7bb698af895af30007f2034e554a3d999090dd2a (diff)
downloadvirt-bootstrap.git-78a5313c1076580c4a7308294765c26caa2da127.tar.gz
virt-bootstrap.git-78a5313c1076580c4a7308294765c26caa2da127.tar.xz
virt-bootstrap.git-78a5313c1076580c4a7308294765c26caa2da127.zip
DockerSource: Retrieve manifest before download
Get manifest of Docker image before the calling "skopeo copy" command. The aim of this change is to: - Make available method get_image_details() which could be used to get information about Docker image or detect whether Docker URI is valid and accessible. - Get information about the layers before the download process (skopeo copy) is called.
Diffstat (limited to 'src/virtBootstrap/sources.py')
-rw-r--r--src/virtBootstrap/sources.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py
index 01de443..d943dcc 100644
--- a/src/virtBootstrap/sources.py
+++ b/src/virtBootstrap/sources.py
@@ -222,6 +222,20 @@ def get_image_dir(no_cache=False):
return DEFAULT_IMG_DIR
+def get_image_details(src, raw=False):
+ """
+ Return details of container image from "skopeo inspect" commnad.
+ """
+ cmd = ['skopeo', 'inspect', src]
+ if raw:
+ cmd.append('--raw')
+ proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
+ output, error = proc.communicate()
+ if error:
+ raise ValueError("Image could not be retrieved:", error)
+ return json.loads(output)
+
+
class FileSource(object):
"""
Extract root filesystem from file.
@@ -295,6 +309,8 @@ class DockerSource(object):
self.url = "docker://" + registry + image
self.images_dir = get_image_dir(self.no_cache)
+ # Retrive manifest from registry
+ self.manifest = get_image_details(self.url, raw=True)
def unpack(self, dest):
"""
@@ -319,20 +335,19 @@ class DockerSource(object):
# Run "skopeo copy" command
execute(skopeo_copy)
- # Get the layers list from the manifest
- manifest_file = open(self.images_dir + "/manifest.json", "r")
- manifest = json.load(manifest_file)
+ # Remove the manifest file as it is not needed
+ os.remove(os.path.join(self.images_dir, "manifest.json"))
# Layers are in order - root layer first
# Reference:
# https://github.com/containers/image/blob/master/image/oci.go#L100
if self.output_format == 'dir':
logger.info("Extracting container layers")
- untar_layers(manifest['layers'], self.images_dir, dest)
+ untar_layers(self.manifest['layers'], self.images_dir, dest)
elif self.output_format == 'qcow2':
logger.info("Extracting container layers into qcow2 images")
- extract_layers_in_qcow2(manifest['layers'], self.images_dir,
- dest)
+ extract_layers_in_qcow2(self.manifest['layers'],
+ self.images_dir, dest)
else:
raise Exception("Unknown format:" + self.output_format)