image-info: add ability to read container images

Add support for reporting the install container images in an image.
NB: this does not use `podman` but reads the overlay storage
directly and therefore does currently not take additional image
locations or different storage drivers into account. For now this
is not a problem since we don't support any of that.
This commit is contained in:
Christian Kellner 2022-07-11 18:04:18 +02:00 committed by Ondřej Budai
parent 0d4fac101c
commit fdb530e29d

View file

@ -161,6 +161,43 @@ def subprocess_check_output(argv, parse_fn=None):
return parse_fn(output) if parse_fn else output
def read_container_images(tree):
"""
Read installed containers
Returns: a dictionary listing the container images in the format
like `podman images --format json` but with less information.
NB: The parsing is done "manually" since running `podman` in the
chroot does not work.
"""
images = []
images_index = os.path.join("overlay-images", "images.json")
for d in ("/var/lib/containers/storage", ):
path = os.path.join(tree, d.lstrip("/"), images_index)
try:
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
except FileNotFoundError:
continue
for image in data:
img = {
"Id": image["id"],
"Digest": image["digest"],
"Names": image["names"],
}
created = image.get("created")
if created:
img["Created"] = created
images.append(img)
return images
def read_image_format(device):
"""
Read image format.
@ -2274,6 +2311,10 @@ def append_filesystem(report, tree, *, is_ostree=False):
if cloud_init_configs:
report["cloud-init"] = cloud_init_configs
container_images = read_container_images(tree)
if container_images:
report["container-images"] = container_images
dnf_conf = read_dnf_conf(tree)
if dnf_conf:
report["dnf"] = dnf_conf