From 69c034fdf3c4fff49ff749925113e36d9d8e9bbf Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Jul 17 2025 16:07:31 +0000 Subject: containers: Add annotations to both the image index and the manifests Quay says you can add annotations to expire images, but doing this in the image index doesn't appear to do anything. Maybe the manifest is where they're supposed to go? Signed-off-by: Jeremy Cline --- diff --git a/fedora-image-uploader/fedora_image_uploader/handler.py b/fedora-image-uploader/fedora_image_uploader/handler.py index 3027a67..ef4bf4c 100644 --- a/fedora-image-uploader/fedora_image_uploader/handler.py +++ b/fedora-image-uploader/fedora_image_uploader/handler.py @@ -56,6 +56,7 @@ class FatManifest: It contains an "image index" pointing to multiple individual image manifests, one per arch, so forming a multiple-architecture manifest. + See https://specs.opencontainers.org/image-spec/image-index/ See https://specs.opencontainers.org/image-spec/manifest/. """ @@ -67,8 +68,15 @@ class FatManifest: del self.index["annotations"] except KeyError: pass + for manifest in self.index["manifests"]: + try: + del manifest["annotations"] + except KeyError: + pass else: self.index["annotations"] = annotations + for manifest in self.index["manifests"]: + manifest["annotations"] = annotations def as_json(self) -> bytes: return json.dumps(self.index, indent=4).encode("utf8") diff --git a/fedora-image-uploader/tests/test_handler.py b/fedora-image-uploader/tests/test_handler.py index 774aa11..c359b46 100644 --- a/fedora-image-uploader/tests/test_handler.py +++ b/fedora-image-uploader/tests/test_handler.py @@ -252,14 +252,14 @@ def test_containers( expdigest = "sha256:da3ea76329f68466e4ebb8e64ed26af1f4df902faee63aed88ff39f40d20fe03" explen = 1409 elif len(arches) == 4 and "annotations" in blob: - expdigest = "sha256:ef9795771ddd3acd948b67a9b666fc71afcfa36d34f59cbddb6e3d9f88d84a25" - explen = 1473 + expdigest = "sha256:002a997e0d7857d3ff583bc404e865dd5d32d16b9d18fa87dc04ca997f3297ad" + explen = 1825 elif len(arches) == 2 and "annotations" not in blob: expdigest = "sha256:7e1f3e15a3c41961e308487c9cccf09b40cb4743fa1f134ac9620b019dd392af" explen = 759 elif len(arches) == 2 and "annotations" in blob: - expdigest = "sha256:f2d41c88156c6307afc98607a8bab3bbb7e1c7811907e80dff883eaed399045c" - explen = 823 + expdigest = "sha256:974eb69187f6c2022819e46f3b73af1e4348bdca68d020910cc398cb594bce01" + explen = 999 else: expdigest = f"FIXME PLEASE UPDATE FOR {str(len(arches))} ARCHES" explen = 0 @@ -477,7 +477,21 @@ def test_run_error(caplog): def test_manifest_annotations(): """Test annotations can be added or removed from an index""" - manifest = FatManifest(index={"not": "real"}) + manifest = FatManifest( + index={ + "schemaVersion": 2, + "manifests": [ + { + "mediaType": "application/vnd.oci.image.manifest.v1+json", + "size": 7143, + "digest": ( + "sha256:e692418e4cbaf90ca69d05a66403747baa33ee08806650b51fab815ad7fc331f" + ), + "platform": {"architecture": "ppc64le", "os": "linux"}, + } + ], + } + ) # Setting it to none even when there are no annotations should be fine manifest.annotations(None) @@ -485,9 +499,13 @@ def test_manifest_annotations(): manifest.annotations({"a": "note"}) assert "annotations" in manifest.index assert manifest.index["annotations"] == {"a": "note"} + for m in manifest.index["manifests"]: + assert m["annotations"] == {"a": "note"} manifest.annotations(None) assert "annotations" not in manifest.index + for m in manifest.index["manifests"]: + assert "annotations" not in m def test_manifest_write_to_dir():