From 6ea8ea98da89eb498d92d5b6ad554ad33dd45fc7 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Sat, 26 Aug 2017 00:34:16 +0200 Subject: [PATCH] syscontainers: use Skopeo copy to pull images New versions of Skopeo support "ostree" as a destination for copy. The missing layers are written directly to the OSTree storage without any additional handling from atomic. Check if the used version of Skopeo has support for ostree and use "skopeo copy" in this case. In future we might drop completely the other code path and assume ostree is always supported. Signed-off-by: Giuseppe Scrivano Closes: #1082 Approved by: baude --- Atomic/syscontainers.py | 22 ++++++++++++++++++++++ Atomic/util.py | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Atomic/syscontainers.py b/Atomic/syscontainers.py index 5198804..ebe4eb4 100644 --- a/Atomic/syscontainers.py +++ b/Atomic/syscontainers.py @@ -1821,6 +1821,28 @@ Warning: You may want to modify `%s` before starting the service""" % os.path.jo current_rev = repo.resolve_rev(imagebranch, True) if not upgrade and current_rev[1]: return False + + can_use_skopeo_copy = util.check_output([util.SKOPEO_PATH, "copy", "--help"]).decode().find("ostree") >= 0 + + if can_use_skopeo_copy: + return self._check_system_oci_image_skopeo_copy(repo, img) + return self._check_system_oci_image_no_skopeo_copy(repo, img, imagebranch) + + def _check_system_oci_image_skopeo_copy(self, repo, img): + repo = self.get_ostree_repo_location() + + checkout = self._get_system_checkout_path() + destdir = checkout if os.path.exists(checkout) else None + temp_dir = tempfile.mkdtemp(prefix=".", dir=destdir) + + destination = "ostree:{}@{}".format(img, repo) + try: + util.skopeo_copy("docker://" + img, destination, dest_ostree_tmp_dir=temp_dir) + finally: + shutil.rmtree(temp_dir, ignore_errors=True) + return True + + def _check_system_oci_image_no_skopeo_copy(self, repo, img, imagebranch): try: manifest = self._skopeo_get_manifest(img) except ValueError: diff --git a/Atomic/util.py b/Atomic/util.py index 84f9c03..ba34a07 100644 --- a/Atomic/util.py +++ b/Atomic/util.py @@ -400,7 +400,7 @@ def skopeo_manifest_digest(manifest_file, debug=False): return check_output(cmd).rstrip().decode() def skopeo_copy(source, destination, debug=False, sign_by=None, insecure=False, policy_filename=None, - username=None, password=None, gpghome=None): + username=None, password=None, gpghome=None, dest_ostree_tmp_dir=None): cmd = [SKOPEO_PATH] if policy_filename: @@ -421,6 +421,9 @@ def skopeo_copy(source, destination, debug=False, sign_by=None, insecure=False, if sign_by: cmd = cmd + ['--sign-by', sign_by] + + if dest_ostree_tmp_dir: + cmd = cmd + ['--dest-ostree-tmp-dir', dest_ostree_tmp_dir] cmd = cmd + [source, destination] if debug: write_out("Executing: {}".format(" ".join(cmd)))