Merge branch 'CPC-8952-make-sbom-optional' into ubuntu/master

This commit is contained in:
michael.hudson@canonical.com 2026-02-20 12:42:04 +13:00
commit 2579dc30cb
No known key found for this signature in database
GPG Key ID: 80E627A0AB757E23

View File

@ -44,6 +44,7 @@ create_manifest() {
local base_default_sbom_name="ubuntu-cloud-image-$(grep "VERSION_ID" $chroot_root/etc/os-release | cut --delimiter "=" --field 2 | tr -d '"')-${ARCH}-$(date +%Y%m%dT%H:%M:%S)" local base_default_sbom_name="ubuntu-cloud-image-$(grep "VERSION_ID" $chroot_root/etc/os-release | cut --delimiter "=" --field 2 | tr -d '"')-${ARCH}-$(date +%Y%m%dT%H:%M:%S)"
local sbom_file_name=${3:-"${base_default_sbom_name}.spdx"} local sbom_file_name=${3:-"${base_default_sbom_name}.spdx"}
local sbom_document_name=${4:-"${base_default_sbom_name}"} local sbom_document_name=${4:-"${base_default_sbom_name}"}
local should_include_sbom=${5:-"true"}
local sbom_log=${sbom_document_name}.log local sbom_log=${sbom_document_name}.log
echo "create_manifest chroot_root: ${chroot_root}" echo "create_manifest chroot_root: ${chroot_root}"
dpkg-query --show --admindir="${chroot_root}/var/lib/dpkg" > ${target_file} dpkg-query --show --admindir="${chroot_root}/var/lib/dpkg" > ${target_file}
@ -54,22 +55,26 @@ create_manifest() {
echo "create_manifest creating file listing." echo "create_manifest creating file listing."
local target_filelist=${2%.manifest}.filelist local target_filelist=${2%.manifest}.filelist
(cd "${chroot_root}" && find -xdev) | sort > "${target_filelist}" (cd "${chroot_root}" && find -xdev) | sort > "${target_filelist}"
# only creating sboms for CPC project at this time if [ "$should_include_sbom" = "true" ]; then
if [[ ! $(which cpc-sbom) ]]; then # only creating sboms for CPC project at this time
# ensure the tool is installed if [[ ! $(which cpc-sbom) ]]; then
sudo snap install --classic --edge cpc-sbom # ensure the tool is installed
fi sudo snap install --classic --edge cpc-sbom
# generate the SBOM fi
cpc-sbom --rootdir ${chroot_root} --ignore-copyright-parsing-errors --ignore-copyright-file-not-found-errors --document-name ${sbom_document_name} >"${sbom_file_name}" 2>"${sbom_log}" # generate the SBOM
SBOM_GENERATION_EXIT_CODE=$? cpc-sbom --rootdir ${chroot_root} --ignore-copyright-parsing-errors --ignore-copyright-file-not-found-errors --document-name ${sbom_document_name} >"${sbom_file_name}" 2>"${sbom_log}"
if [[ ${SBOM_GENERATION_EXIT_CODE} != "0" ]]; then SBOM_GENERATION_EXIT_CODE=$?
# check for failure and print log if [[ ${SBOM_GENERATION_EXIT_CODE} != "0" ]]; then
echo "ERROR: SBOM generation failed. See ${sbom_log}" # check for failure and print log
cat "$sbom_log" echo "ERROR: SBOM generation failed. See ${sbom_log}"
exit 1 cat "$sbom_log"
exit 1
else
echo "SBOM generation succeeded. see ${sbom_log} for details"
fi
else else
echo "SBOM generation succeeded. see ${sbom_log} for details" echo "SBOM generation skipped"
fi fi
fi fi
echo "create_manifest finished" echo "create_manifest finished"
} }