From 6bdff0a019b7ecc15b97d54e6e391e417a980871 Mon Sep 17 00:00:00 2001 From: jbtrystram Date: Wed, 7 Oct 2026 15:19:39 +0200 Subject: [PATCH] cmd-import: use OCI artifactType field to pull disk images Instead of abusing the platform field, switch to the more default `artifactType` field. The value we put in there is still custom to our build pipeline but it won't break any tooling as this field is meant for this type of usage. See https://github.com/joelcapitao/bib-fcos-experimentation/pull/133 Assisted-by: Opencode.ai --- src/cmd-import | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/cmd-import b/src/cmd-import index 345b439073..606f391b88 100755 --- a/src/cmd-import +++ b/src/cmd-import @@ -7,8 +7,10 @@ it into a `cosa build`, as if one did `cosa build ostree`. One can then e.g. If the source image is an OCI image index that contains disk image artifacts (entries with artifactType matching application/vnd.diskimage.*), they are -automatically discovered. The platform.os field is used as the cosa platform -name (e.g. qemu, metal) and the artifactType to derive the file extension. +automatically discovered. The artifactType is of the form +application/vnd.diskimage.. (e.g. +application/vnd.diskimage.qemu.qcow2) and is used to derive both the cosa +platform name (e.g. qemu, metal) and the file extension. Use --download to pull disk image blobs and populate the build's meta.json. ''' @@ -221,17 +223,22 @@ def oci_goarch_to_basearch(goarch): return OCI_GOARCH_TO_BASEARCH.get(goarch, goarch) -def artifact_type_to_extension(artifact_type): - """Convert an OCI artifactType to a file extension. +def artifact_type_to_platform_and_extension(artifact_type): + """Parse an OCI artifactType into its cosa platform name and file extension. - e.g. 'application/vnd.diskimage.qcow2' -> 'qcow2' - 'application/vnd.diskimage.raw.gzip' -> 'raw.gz' + e.g. 'application/vnd.diskimage.qemu.qcow2' -> ('qemu', 'qcow2') + 'application/vnd.diskimage.metal.raw.gzip' -> ('metal', 'raw.gz') """ if not artifact_type.startswith(DISK_IMAGE_ARTIFACT_PREFIX): raise ValueError(f"Unknown artifactType: {artifact_type}") - suffix = artifact_type[len(DISK_IMAGE_ARTIFACT_PREFIX):] + remainder = artifact_type[len(DISK_IMAGE_ARTIFACT_PREFIX):] + if '.' not in remainder: + raise ValueError(f"Malformed artifactType (missing platform): {artifact_type}") + platform_name, suffix = remainder.split('.', 1) + if not platform_name or not suffix: + raise ValueError(f"Malformed artifactType (missing platform): {artifact_type}") suffix = suffix.replace('gzip', 'gz') - return suffix + return platform_name, suffix def strip_transport_prefix(ref): @@ -290,18 +297,12 @@ def discover_disk_image_artifacts(index_manifest): goarch = platform.get('architecture', '') arch = oci_goarch_to_basearch(goarch) - platform_name = platform.get('os', '') digest = entry.get('digest') - if not platform_name: - raise ValueError( - f"Malformed manifest entry: missing platform.os " - f"(digest: {digest or 'unknown'})") - if not digest: raise ValueError( - f"Malformed manifest entry for {platform_name}: missing digest") + f"Malformed manifest entry: missing digest (artifactType: {artifact_type})") - extension = artifact_type_to_extension(artifact_type) + platform_name, extension = artifact_type_to_platform_and_extension(artifact_type) artifacts.append({ 'platform': platform_name,