Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd-build: Conditionally change the packing structure of container-image #3445

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/builds/cosa_v1.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package builds

// generated by 'make schema'
// source hash: 2cd4fe2a0c72e389ee6cb2b906653cdfd33f87b87d7e2e261fce4615a8c0272a
// source hash: a5fec50536bd4c2eed006dfb897b3b40fdf50393a0e3e32edf874b4e200e4e4d

type AdvisoryDiff []AdvisoryDiffItems

Expand Down Expand Up @@ -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"`
Expand Down
11 changes: 9 additions & 2 deletions pkg/builds/schema_doc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Generated by ./generate-schema.sh
// Source hash: 2cd4fe2a0c72e389ee6cb2b906653cdfd33f87b87d7e2e261fce4615a8c0272a
// Source hash: a5fec50536bd4c2eed006dfb897b3b40fdf50393a0e3e32edf874b4e200e4e4d
// DO NOT EDIT

package builds
Expand Down Expand Up @@ -479,7 +479,8 @@ var generatedSchemaJSON = `{
"vmware",
"vultr",
"qemu-secex",
"ignition-gpg-key"
"ignition-gpg-key",
"oci-manifest"
],
"properties": {
"ostree": {
Expand All @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions src/cmd-build
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ if [ "${commit}" == "${previous_commit}" ] && \
ostree_tarfile_path=$(jq -r '.images.ostree.path' < "${previous_builddir}/meta.json")
cp-reflink "${previous_builddir}/${previous_ostree_tarfile_path}" "${ostree_tarfile_path}"
ostree_tarfile_sha256=$(jq -r '.images.ostree.sha256' < "${previous_builddir}/meta.json")

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}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stuff looks duplicated? Do we need this here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I see why now, we need it in both paths, but maybe extract a helper function for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but that's hard because we currently set global variables, and fixing that is messy.


# backcompat: allow older build without this field
if [ "${ostree_tarfile_sha256}" = "null" ]; then
ostree_tarfile_sha256=
Expand All @@ -452,18 +459,33 @@ 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}" \
--label="coreos-assembler.image-input-checksum=${image_input_checksum}" \
--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}"
RishabhSaini marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -507,6 +529,11 @@ cat > tmp/images.json <<EOF
"sha256": "${ostree_tarfile_sha256}",
"size": ${ostree_tarfile_size},
"skip-compression": true
},
"oci-manifest": {
"path": "${ostree_oci_manifest_path}",
"sha256": "${ostree_oci_manifest_sha256}",
"size": ${ostree_oci_manifest_size}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@
"vmware",
"vultr",
"qemu-secex",
"ignition-gpg-key"
"ignition-gpg-key",
"oci-manifest"
],
"properties": {
"ostree": {
Expand All @@ -482,6 +483,12 @@
"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",
Expand Down
Loading