From a80f1053515ec37088ee4699c29d878f4878a1e8 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Thu, 21 Sep 2023 23:40:47 +0200 Subject: [PATCH 1/2] With Podman, save images as oci-archive so they are compressed --- taskboot/docker.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/taskboot/docker.py b/taskboot/docker.py index 5067c53..d774636 100644 --- a/taskboot/docker.py +++ b/taskboot/docker.py @@ -314,6 +314,13 @@ def list_images(self): image["digest"] = image["digest"][7:] return result + def save(self, tags, path): + assert isinstance(tags, list) + assert len(tags) > 0, "Missing tags" + logger.info("Saving image with tags {} to {}".format(", ".join(tags), path)) + command = ["save", "--format", "oci-archive", "--output", path] + tags + self.run(command) + class Skopeo(Tool): """ @@ -361,7 +368,7 @@ def push_archive(self, path, custom_tag=None): "copy", "--authfile", self.auth_file, - "docker-archive:{}".format(path), + "oci-archive:{}".format(path), "docker://{}".format(tag), ] self.run(cmd) From cf2d9c25914f9c43c0b677538ca0024f3b42199b Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 22 Sep 2023 00:01:56 +0200 Subject: [PATCH 2/2] Support reading archive tags from oci-archive format --- taskboot/docker.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/taskboot/docker.py b/taskboot/docker.py index d774636..e92b021 100644 --- a/taskboot/docker.py +++ b/taskboot/docker.py @@ -33,17 +33,22 @@ def read_archive_tags(path): tar = tarfile.open(path) tags = [] try: - manifest_raw = tar.extractfile("manifest.json") - manifest = json.loads(manifest_raw.read().decode("utf-8")) - tags = manifest[0]["RepoTags"] + index_raw = tar.extractfile("index.json") + index = json.loads(index_raw.read().decode("utf-8")) + tags = index["manifests"][0]["annotations"]["org.opencontainers.image.ref.name"] except KeyError: - # Use older image format: - # {"registry.hub.docker.com/xyz/":{"master":"02d3443146cc39d41207919f156869d60942cd3eafeec793a4ac39f905f6f7c6"}} - repositories_raw = tar.extractfile("repositories") - repositories = json.loads(repositories_raw.read().decode("utf-8")) - for repo, tag_and_sha in repositories.items(): - for tag, sha in tag_and_sha.items(): - tags.append("{}:{}".format(repo, tag)) + try: + manifest_raw = tar.extractfile("manifest.json") + manifest = json.loads(manifest_raw.read().decode("utf-8")) + tags = manifest[0]["RepoTags"] + except KeyError: + # Use older image format: + # {"registry.hub.docker.com/xyz/":{"master":"02d3443146cc39d41207919f156869d60942cd3eafeec793a4ac39f905f6f7c6"}} + repositories_raw = tar.extractfile("repositories") + repositories = json.loads(repositories_raw.read().decode("utf-8")) + for repo, tag_and_sha in repositories.items(): + for tag, sha in tag_and_sha.items(): + tags.append("{}:{}".format(repo, tag)) assert len(tags) > 0, "No tags found" return tags