Skip to content

Commit

Permalink
Support untagging OCI images (release-engineering#261)
Browse files Browse the repository at this point in the history
* Support untagging OCI images

* Adjusted checks for manifest media types
  • Loading branch information
midnightercz authored May 23, 2024
1 parent 28033ff commit 40d9059
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions pubtools/_quay/tag_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class TagDocker:
ImageDetails = namedtuple("ImageDetails", ["reference", "manifest", "manifest_type", "digest"])
MANIFEST_LIST_TYPE = "application/vnd.docker.distribution.manifest.list.v2+json"
MANIFEST_V2S2_TYPE = "application/vnd.docker.distribution.manifest.v2+json"
MANIFEST_OCI_LIST_TYPE = "application/vnd.oci.image.index.v1+json"
MANIFEST_OCI_V2S2_TYPE = "application/vnd.oci.image.manifest.v1+json"

def __init__(
self,
Expand Down Expand Up @@ -220,13 +222,21 @@ def get_image_details(self, reference: str, executor: Executor) -> Optional[Imag
raise

manifest_type = manifest["mediaType"]
if manifest_type not in [TagDocker.MANIFEST_V2S2_TYPE, TagDocker.MANIFEST_LIST_TYPE]:
if manifest_type not in [
TagDocker.MANIFEST_V2S2_TYPE,
TagDocker.MANIFEST_LIST_TYPE,
TagDocker.MANIFEST_OCI_V2S2_TYPE,
TagDocker.MANIFEST_OCI_LIST_TYPE,
]:
raise BadPushItem(
"Image {0} has manifest type different than V2S2 or manifest list".format(reference)
)

# Check arch if the image is V2S2 manifest
if manifest["mediaType"] == TagDocker.MANIFEST_V2S2_TYPE:
if manifest["mediaType"] in (
TagDocker.MANIFEST_V2S2_TYPE,
TagDocker.MANIFEST_OCI_V2S2_TYPE,
):
arch = executor.skopeo_inspect(reference)["Architecture"]
# Arch check is not a great way to verify that this is a source image, but there are
# no better options without having build details
Expand Down Expand Up @@ -308,13 +318,19 @@ def tag_remove_calculate_archs(
)

# Scenario 1: source image
if dest_details.manifest_type == TagDocker.MANIFEST_V2S2_TYPE:
if dest_details.manifest_type in (
TagDocker.MANIFEST_V2S2_TYPE,
TagDocker.MANIFEST_OCI_V2S2_TYPE,
):
return self.tag_remove_calculate_archs_source_image(
push_item, source_details, dest_details
)

# Scenario 2: multiarch image
if dest_details.manifest_type == TagDocker.MANIFEST_LIST_TYPE:
if dest_details.manifest_type in (
TagDocker.MANIFEST_LIST_TYPE,
TagDocker.MANIFEST_OCI_LIST_TYPE,
):
return self.tag_remove_calculate_archs_multiarch_image(
push_item, source_details, dest_details
)
Expand Down

0 comments on commit 40d9059

Please sign in to comment.