Skip to content

Commit 1586c7a

Browse files
authored
Merge pull request #1213 from c-po/sbom
sbom: T8542: change result filenames to match ISO image filename
2 parents 13b4286 + 819e3c6 commit 1586c7a

3 files changed

Lines changed: 67 additions & 49 deletions

File tree

docker/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ RUN apt-get update && apt-get install -y \
110110
gdisk \
111111
sbsigntool \
112112
dosfstools \
113-
kpartx
113+
kpartx \
114+
xorriso
114115

115116
# Packages for TPM test
116117
RUN apt-get update && apt-get install -y swtpm

scripts/image-build/build-vyos-image

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -729,23 +729,25 @@ Pin-Priority: 600
729729
# Now create SBOM
730730
syft_target_dir = 'chroot'
731731
syft_base_path = os.getcwd() + f'/{syft_target_dir}'
732+
base_filename = iso_file.rstrip('.iso')
732733
cmd = [['syft', syft_target_dir,
733734
'--source-name', 'VyOS', '--source-version', version,
734-
'-o', f'cyclonedx-json=vyos-{version}.cdx.json',
735-
'-o', f'spdx-json=vyos-{version}.spdx.json']]
735+
'-o', f'cyclonedx-json={base_filename}.cdx.json',
736+
'-o', f'spdx-json={base_filename}.spdx.json']]
736737

737738
# syft bug for CycloneDX https://github.com/anchore/syft/issues/4592#issuecomment-4567247328
738-
cmd.append(['sed', '-i', '-e', f's@{syft_base_path}@@g', f'vyos-{version}.cdx.json'])
739-
cmd.append(['sed', '-i', '-e', f's@{syft_base_path}@//@g', f'vyos-{version}.spdx.json'])
739+
cmd.append(['sed', '-i', '-e', f's@{syft_base_path}@@g', f'{base_filename}.cdx.json'])
740+
cmd.append(['sed', '-i', '-e', f's@{syft_base_path}@//@g', f'{base_filename}.spdx.json'])
740741

741742
for c in cmd:
742-
print(c)
743743
with subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
744744
text=True, bufsize=1) as p:
745745
for line in p.stdout:
746746
sys.stdout.write(line)
747747
sys.stdout.flush()
748748
p.wait()
749+
print("I: Finished SBOM generation")
750+
749751

750752
# If the flavor has `image_format = "iso"`, then the work is done.
751753
# If not, build additional flavors from the ISO.

scripts/iso-to-oci

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,89 @@
11
#!/bin/bash
22

3-
function cleanup() {
4-
if [[ -d $ROOTFS ]]; then
5-
rm -rf $ROOTFS
6-
fi
7-
if [[ -d $UNSQUASHFS ]]; then
8-
rm -rf $UNSQUASHFS
3+
set -euo pipefail
4+
5+
cleanup() {
6+
if [[ -n "${WORKDIR:-}" && -d "${WORKDIR:-}" ]]; then
7+
rm -rf "${WORKDIR}"
98
fi
109
}
1110

12-
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
13-
echo "Not running as root"
14-
exit 1
15-
fi
16-
17-
if [ "$#" -ne 1 ]; then
18-
echo "Illegal number of parameters"
19-
exit 1
11+
if [[ "$#" -ne 1 ]]; then
12+
echo "Usage: $0 <path-to-iso>"
13+
exit 2
2014
fi
2115

2216
ISO=$1
23-
ROOTFS=rootfs
24-
UNSQUASHFS=unsquashfs
25-
26-
if [ ! -f "$ISO" ]; then
27-
echo "E: Unable to find VyOS ISO image \"$ISO\" required for conversion"
28-
exit 1
17+
if [[ ! -f "$ISO" ]]; then
18+
echo "E: ISO file not found: $ISO"
19+
exit 2
2920
fi
3021

3122
# ensure clean working directory
3223
cleanup
3324

34-
mkdir $ROOTFS $UNSQUASHFS
35-
echo "I: mount ISO $ISO"
36-
mount -t iso9660 -o loop $ISO $ROOTFS/ >/dev/null 2>&1
25+
if ! command -v xorriso >/dev/null 2>&1; then
26+
echo "E: missing dependency: xorriso"
27+
echo " Install xorriso (recommended) or run inside the vyos-build container."
28+
exit 2
29+
fi
30+
31+
if ! command -v unsquashfs >/dev/null 2>&1; then
32+
echo "E: missing dependency: unsquashfs"
33+
echo " Install squashfs-tools or run inside the vyos-build container."
34+
exit 2
35+
fi
36+
37+
if ! command -v jq >/dev/null 2>&1; then
38+
echo "E: missing dependency: jq"
39+
echo " Install jq or run inside the vyos-build container."
40+
exit 2
41+
fi
42+
43+
WORKDIR="$(mktemp -d -t iso-to-oci.XXXXXXXXXX)"
44+
trap cleanup EXIT
45+
46+
ROOTFS="${WORKDIR}/iso"
47+
UNSQUASHFS="${WORKDIR}/unsquashfs"
48+
mkdir -p "${ROOTFS}/live" "${UNSQUASHFS}"
49+
50+
echo "I: extracting ISO metadata"
51+
xorriso -osirrox on -indev "${ISO}" -extract /version.json "${ROOTFS}/version.json" >/dev/null 2>&1
52+
53+
echo "I: extracting squashfs image"
54+
xorriso -osirrox on -indev "${ISO}" -extract /live/filesystem.squashfs "${ROOTFS}/live/filesystem.squashfs" >/dev/null 2>&1
3755

3856
# create directory, unpack squashfs filesystem, get ISO version
39-
# and unmount ISO
4057
echo "I: extracting squashfs content"
41-
unsquashfs -follow -dest $UNSQUASHFS/ $ROOTFS/live/filesystem.squashfs >/dev/null 2>&1
42-
VERSION=$(jq --raw-output .version $ROOTFS/version.json)
43-
umount $ROOTFS/
58+
unsquashfs -follow -dest "${UNSQUASHFS}/" "${ROOTFS}/live/filesystem.squashfs" >/dev/null 2>&1
59+
VERSION="$(jq --raw-output .version "${ROOTFS}/version.json")"
4460

4561
# fix locales for correct system configuration loading
46-
sed -i 's/^LANG=.*$/LANG=C.UTF-8/' $UNSQUASHFS/etc/default/locale
62+
sed -i 's/^LANG=.*$/LANG=C.UTF-8/' "${UNSQUASHFS}/etc/default/locale"
4763

4864
# optional step: Decrease docker image size by deleting not necessary files for container
49-
rm -rf $UNSQUASHFS/boot/*.img
50-
rm -rf $UNSQUASHFS/boot/*vyos*
51-
rm -rf $UNSQUASHFS/boot/vmlinuz
52-
rm -rf $UNSQUASHFS/lib/firmware/
53-
rm -rf $UNSQUASHFS/usr/lib/x86_64-linux-gnu/libwireshark.so*
54-
rm -rf $UNSQUASHFS/lib/modules/*amd64-vyos
55-
rm -rf $UNSQUASHFS/root/.gnupg
65+
rm -rf "${UNSQUASHFS}/boot"
66+
rm -rf "${UNSQUASHFS}/lib/firmware/"
67+
rm -rf "${UNSQUASHFS}/usr/lib/x86_64-linux-gnu/libwireshark.so*"
68+
rm -rf "${UNSQUASHFS}/lib/modules/*-vyos"
69+
rm -rf "${UNSQUASHFS}/root/.gnupg"
5670

5771
# delete features not supported in container - only remove the node.def files,
5872
# this is sufficient to not make the feature pop up on the CLI
59-
rm -rf $UNSQUASHFS/opt/vyatta/share/vyatta-cfg/templates/container
60-
rm -rf $UNSQUASHFS/opt/vyatta/share/vyatta-cfg/templates/system/option/kernel
61-
rm -rf $UNSQUASHFS/opt/vyatta/share/vyatta-cfg/templates/system/option/startup-beep
62-
rm -rf $UNSQUASHFS/opt/vyatta/share/vyatta-cfg/templates/system/option/root-partition-auto-resize
63-
rm -rf $UNSQUASHFS/opt/vyatta/share/vyatta-cfg/templates/system/option/reboot-on-panic
64-
rm -rf $UNSQUASHFS/opt/vyatta/share/vyatta-cfg/templates/system/option/performance
73+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/container"
74+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/console"
75+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/kernel"
76+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/startup-beep"
77+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/root-partition-auto-resize"
78+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/reboot-on-panic"
79+
rm -rf "${UNSQUASHFS}/opt/vyatta/share/vyatta-cfg/templates/system/option/performance"
6580

6681
# create a symbolic link to the configuration
67-
ln -s /opt/vyatta/etc/config $UNSQUASHFS/config
82+
ln -s /opt/vyatta/etc/config "${UNSQUASHFS}/config"
6883

6984
# create docker image
7085
echo "I: generate OCI container image vyos-$VERSION.tar"
71-
tar -C unsquashfs -c . -f vyos-$VERSION.tar
86+
tar -C "${UNSQUASHFS}" -c . -f "vyos-${VERSION}.tar"
7287

7388
echo "I: to import the previously generated OCI image to your local images run:"
7489
echo ""

0 commit comments

Comments
 (0)