Skip to content

Commit 75a495b

Browse files
committed
sbom: T8542: create during ISO assembly
1 parent 3f8ea66 commit 75a495b

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

docker/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ RUN apt-get update && apt-get install -y \
348348
debmake \
349349
python3-debian
350350

351+
# Install syft binary required for SBOM generation
352+
RUN cd /tmp && curl -sSfL -o syft.tar.gz \
353+
https://cdn.vyos.io/tools/syft_1.44.0_linux_$(dpkg-architecture -qDEB_HOST_ARCH).tar.gz; \
354+
tar --extract --file=syft.tar.gz syft; mv syft /usr/local/bin/
355+
351356
# Allow password-less 'sudo' for all users in group 'sudo'
352357
RUN sed "s/^%sudo.*/%sudo\tALL=(ALL) NOPASSWD:ALL/g" -i /etc/sudoers && \
353358
echo "vyos_bld\tALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && \

scripts/image-build/build-vyos-image

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
#
3-
# Copyright (C) 2022-2024 VyOS maintainers and contributors
3+
# Copyright VyOS maintainers and contributors <maintainers@vyos.io>
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License version 2 or later as
@@ -17,7 +17,6 @@
1717
# File: build-vyos-image
1818
# Purpose: builds VyOS images using a fork of Debian's live-build tool
1919

20-
# Import Python's standard library modules
2120
import re
2221
import os
2322
import sys
@@ -31,11 +30,11 @@ import argparse
3130
import datetime
3231
import functools
3332
import string
33+
import subprocess
3434

3535
class ImageBuildError(Exception):
3636
pass
3737

38-
3938
# argparse converts hyphens to underscores,
4039
# so for lookups in the original options hash we have to convert them back
4140
def field_to_option(s):
@@ -722,11 +721,32 @@ Pin-Priority: 600
722721
cmd("lb build 2>&1")
723722

724723
# Copy the image
725-
shutil.copy("live-image-{0}.hybrid.iso".format(build_config["architecture"]), iso_file)
724+
shutil.copy(f'live-image-{build_config["architecture"]}.hybrid.iso', iso_file)
726725

727726
# Add the image to the manifest
728727
manifest['artifacts'].append(iso_file)
729728

729+
# Now create SBOM
730+
syft_target_dir = 'chroot'
731+
syft_base_path = os.getcwd() + f'/{syft_target_dir}'
732+
cmd = [['syft', syft_target_dir,
733+
'--source-name', 'VyOS', '--source-version', version,
734+
'-o', f'cyclonedx-json=vyos-{version}.cdx.json',
735+
'-o', f'spdx-json=vyos-{version}.spdx.json']]
736+
737+
# 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'])
740+
741+
for c in cmd:
742+
print(c)
743+
with subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
744+
text=True, bufsize=1) as p:
745+
for line in p.stdout:
746+
sys.stdout.write(line)
747+
sys.stdout.flush()
748+
p.wait()
749+
730750
# If the flavor has `image_format = "iso"`, then the work is done.
731751
# If not, build additional flavors from the ISO.
732752
if build_config["image_format"] != ["iso"]:

0 commit comments

Comments
 (0)