Skip to content
Open
Changes from 2 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
32 changes: 32 additions & 0 deletions build-recipe-mkosi
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,38 @@ recipe_build_mkosi() {
if [ -n "$RELEASE" ]; then
image_version="--image-version=${RELEASE}"
fi

for format in $(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" buildflags+ sbom | sort -u) ; do
# workaround as /.build/ is not available in chroot
mkdir -p "$TOPDIR/scripts"
cp -r "/.build/" "$TOPDIR/scripts"
chmod +x "$TOPDIR/scripts/.build/generate_sbom"
mkdir -p $BUILD_ROOT/$TOPDIR/SOURCES/mkosi.conf.d/99-sbom/
IMAGENAME=$(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" eval '%{?mkosi_sbom_name}' || "image")
IMAGENAME=${IMAGENAME:-image}
echo "IMAGENAME= $IMAGENAME"
echo "generating script for sbom $format"
cat << EOF >> $BUILD_ROOT/$TOPDIR/SOURCES/mkosi.conf.d/99-sbom/mkosi.finalize
#!/usr/bin/bash
# script generated by build-receipe-mkosi for sbom buildflags
Copy link
Contributor

Choose a reason for hiding this comment

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

receipe -> recipe

echo "Generating $format sbom file"
imgname="$IMAGENAME.${RELEASE}"
ln -sf \$BUILDROOT "$IMAGENAME"
export PERL5LIB="$TOPDIR/scripts/.build"
$TOPDIR/scripts/.build/generate_sbom \
--dist "$TOPDIR/scripts/$BUILD_DIST" \
--configdir "$TOPDIR/scripts/$CONFIG_DIR" \
--archpath "$BUILD_ARCH" \
--format "$format" \
--dir "$IMAGENAME" > "\$OUTPUTDIR/\${imgname}${buildnum}.${format/cyclonedx/cdx}.json"
pushd \$OUTPUTDIR >/dev/null
/usr/bin/sha256sum "\${imgname}${buildnum}.${format/cyclonedx/cdx}.json" > "\${imgname}${buildnum}.${format/cyclonedx/cdx}.json".sh256
Copy link
Contributor

Choose a reason for hiding this comment

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

.sh256 -> .sha256

popd >/dev/null
EOF
chmod +x $BUILD_ROOT/$TOPDIR/SOURCES/mkosi.conf.d/99-sbom/mkosi.finalize
cat $BUILD_ROOT/$TOPDIR/SOURCES/mkosi.conf.d/99-sbom/mkosi.finalize
done

set -- mkosi \
--directory "$TOPDIR/SOURCES" \
--default \
Expand Down