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,25 @@ 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+ cmd = ['syft' , '.' , '--source-name' , 'VyOS' , '--source-version' , version ,
731+ '-o' , f'cyclonedx-json={ version } .cdx.json' ,
732+ '-o' , f'spdx-json={ version } .spdx.json' ]
733+ with subprocess .Popen (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT ,
734+ text = True , bufsize = 1 ) as p :
735+ for line in p .stdout :
736+ sys .stdout .write (line )
737+ sys .stdout .flush ()
738+
739+ rc = p .wait ()
740+ if rc != 0 :
741+ raise subprocess .CalledProcessError (rc , cmd )
742+
730743 # If the flavor has `image_format = "iso"`, then the work is done.
731744 # If not, build additional flavors from the ISO.
732745 if build_config ["image_format" ] != ["iso" ]:
0 commit comments