Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions taskboot/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -314,6 +319,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):
"""
Expand Down Expand Up @@ -361,7 +373,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)
Expand Down