summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-04 16:24:19 +0100
committerCédric Bosdonnat <cbosdonnat@suse.com>2017-07-05 09:48:23 +0200
commit04dfccb8acda9d79a3a7dccb16a5670fb3f279e7 (patch)
tree9b67c49a78cbedfdd96d503d6487a3679ffd1428
parentc1cdbeee437c5c82d9928e73211f6bac91259dcc (diff)
downloadvirt-bootstrap.git-04dfccb8acda9d79a3a7dccb16a5670fb3f279e7.tar.gz
virt-bootstrap.git-04dfccb8acda9d79a3a7dccb16a5670fb3f279e7.tar.xz
virt-bootstrap.git-04dfccb8acda9d79a3a7dccb16a5670fb3f279e7.zip
DockerSource: Encapsulate skopeo copy in a method
-rw-r--r--src/virtBootstrap/sources.py44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py
index 0992704..78f6be3 100644
--- a/src/virtBootstrap/sources.py
+++ b/src/virtBootstrap/sources.py
@@ -338,6 +338,28 @@ class DockerSource(object):
file_path = os.path.join(self.images_dir, layer_sum + '.tar')
self.layers.append([sum_type, layer_sum, file_path, layer['size']])
+ def download_image(self):
+ """
+ Download image layers using "skopeo copy".
+ """
+ # Note: we don't want to expose --src-cert-dir to users as
+ # they should place the certificates in the system
+ # folders for broader enablement
+ skopeo_copy = ["skopeo", "copy", self.url, "dir:" + self.images_dir]
+
+ if self.insecure:
+ skopeo_copy.append('--src-tls-verify=false')
+ if self.username:
+ if not self.password:
+ self.password = getpass.getpass()
+ skopeo_copy.append('--src-creds={}:{}'.format(self.username,
+ self.password))
+ logger.info("Downloading container image")
+ # Run "skopeo copy" command
+ execute(skopeo_copy)
+ # Remove the manifest file as it is not needed
+ os.remove(os.path.join(self.images_dir, "manifest.json"))
+
def unpack(self, dest):
"""
Extract image files from Docker image
@@ -345,28 +367,12 @@ class DockerSource(object):
@param dest: Directory path where the files to be extraced
"""
try:
- # Run skopeo copy into a tmp folder
- # Note: we don't want to expose --src-cert-dir to users as
- # they should place the certificates in the system
- # folders for broader enablement
- skopeo_copy = ["skopeo", "copy", self.url, "dir:" + self.images_dir]
-
- if self.insecure:
- skopeo_copy.append('--src-tls-verify=false')
- if self.username:
- if not self.password:
- self.password = getpass.getpass()
- skopeo_copy.append('--src-creds={}:{}'.format(self.username,
- self.password))
- # Run "skopeo copy" command
- execute(skopeo_copy)
-
- # 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
+ self.download_image()
+
+ # Unpack to destination directory
if self.output_format == 'dir':
logger.info("Extracting container layers")
untar_layers(self.layers, dest)