From 599491ef8aedcbfe692b0f50f422e45e90bcb174 Mon Sep 17 00:00:00 2001 From: RishabhSaini Date: Tue, 2 May 2023 11:41:53 -0400 Subject: [PATCH] cmd-build: Conditionally change the packing structure of container-image When the previous build exists, use its packing structure otherwise container-encapsulate generates a new one --- pkg/builds/cosa_v1.go | 3 ++- pkg/builds/schema_doc.go | 11 +++++++++-- src/cmd-build | 20 ++++++++++++++++++++ src/v1.json | 9 ++++++++- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/pkg/builds/cosa_v1.go b/pkg/builds/cosa_v1.go index 595b9b8e72..85f251d4fa 100644 --- a/pkg/builds/cosa_v1.go +++ b/pkg/builds/cosa_v1.go @@ -1,7 +1,7 @@ package builds // generated by 'make schema' -// source hash: 2cd4fe2a0c72e389ee6cb2b906653cdfd33f87b87d7e2e261fce4615a8c0272a +// source hash: a5fec50536bd4c2eed006dfb897b3b40fdf50393a0e3e32edf874b4e200e4e4d type AdvisoryDiff []AdvisoryDiffItems @@ -106,6 +106,7 @@ type BuildArtifacts struct { Metal *Artifact `json:"metal,omitempty"` Metal4KNative *Artifact `json:"metal4k,omitempty"` Nutanix *Artifact `json:"nutanix,omitempty"` + OciManifest *Artifact `json:"oci-manifest,omitempty"` OpenStack *Artifact `json:"openstack,omitempty"` Ostree Artifact `json:"ostree"` PowerVirtualServer *Artifact `json:"powervs,omitempty"` diff --git a/pkg/builds/schema_doc.go b/pkg/builds/schema_doc.go index 2716cf3395..cda4acdadf 100644 --- a/pkg/builds/schema_doc.go +++ b/pkg/builds/schema_doc.go @@ -1,5 +1,5 @@ // Generated by ./generate-schema.sh -// Source hash: 2cd4fe2a0c72e389ee6cb2b906653cdfd33f87b87d7e2e261fce4615a8c0272a +// Source hash: a5fec50536bd4c2eed006dfb897b3b40fdf50393a0e3e32edf874b4e200e4e4d // DO NOT EDIT package builds @@ -479,7 +479,8 @@ var generatedSchemaJSON = `{ "vmware", "vultr", "qemu-secex", - "ignition-gpg-key" + "ignition-gpg-key", + "oci-manifest" ], "properties": { "ostree": { @@ -488,6 +489,12 @@ var generatedSchemaJSON = `{ "title": "OSTree", "$ref": "#/definitions/artifact" }, + "oci-manifest": { + "$id": "#/properties/images/properties/oci-manifest", + "type": "object", + "title": "OCI Manifest", + "$ref": "#/definitions/artifact" + }, "dasd": { "$id": "#/properties/images/properties/dasd", "type": "object", diff --git a/src/cmd-build b/src/cmd-build index fd375997c6..95459778eb 100755 --- a/src/cmd-build +++ b/src/cmd-build @@ -452,6 +452,15 @@ else "--label=io.openshift.build.versions=machine-os=${buildid}" ) fi + + last_build_manifest=() + # Use the last stable release if buildfetch used + if [ -n "${PARENT_BUILD}" ]; then + last_build_manifest+=("--previous_build_manifest=${parent_builddir}/${name}-${PARENT_BUILD}-ostree.${basearch}-manifest.json") + # Use the previous local build + elif [ -n "${previous_build}" ]; then + last_build_manifest+=("--previous_build_manifest=${previous_builddir}/${name}-${previous_build}-ostree.${basearch}-manifest.json") + fi runv rpm-ostree compose container-encapsulate --max-layers="$MAX_OSTREECONTAINER_LAYERS" --format-version=1 \ --repo="${tmprepo}" \ --label="coreos-assembler.image-config-checksum=${image_config_checksum}" \ @@ -459,11 +468,17 @@ else --label="org.opencontainers.image.source=${gitsrc}" \ --label="org.opencontainers.image.revision=${config_gitrev}" \ --copymeta-opt=fedora-coreos.stream \ + "${last_build_manifest[@]}" \ "${labels[@]}" \ "${buildid}" \ oci-archive:"${ostree_tarfile_path}".tmp:latest /usr/lib/coreos-assembler/finalize-artifact "${ostree_tarfile_path}"{.tmp,} ostree_tarfile_sha256=$(sha256sum "${ostree_tarfile_path}" | awk '{print$1}') + ostree_oci_manifest_path="${name}-${buildid}-ostree.${basearch}-manifest.json" + skopeo inspect --raw oci-archive:"${ostree_tarfile_path}" > tmp/manifest.json + /usr/lib/coreos-assembler/finalize-artifact tmp/manifest.json "${ostree_oci_manifest_path}" + ostree_oci_manifest_sha256=$(sha256sum "${ostree_oci_manifest_path}" | awk '{print$1}') + ostree_oci_manifest_size=$(stat --format=%s "${ostree_oci_manifest_path}") fi # The base metadata, plus locations for code sources. @@ -507,6 +522,11 @@ cat > tmp/images.json <