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
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
2120import re
2221import os
2322import sys
@@ -31,11 +30,11 @@ import argparse
3130import datetime
3231import functools
3332import string
33+ import subprocess
3434
3535class 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
4140def 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