From 585d349d0f02018afcff348d2a5e85f3fc64f4b1 Mon Sep 17 00:00:00 2001 From: Simon de Vlieger Date: Mon, 20 Jan 2025 15:35:47 +0100 Subject: [PATCH] image-builder: `--extra-artifacts` split Split out `--extra-artifacts` into `--with-sbom` and `--with-manifest`. Signed-off-by: Simon de Vlieger --- cmd/image-builder/main.go | 17 ++++++++++++----- cmd/image-builder/main_test.go | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cmd/image-builder/main.go b/cmd/image-builder/main.go index 745bd33..43af781 100644 --- a/cmd/image-builder/main.go +++ b/cmd/image-builder/main.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "os" - "slices" "github.com/sirupsen/logrus" "github.com/spf13/cobra" @@ -86,7 +85,7 @@ func cmdManifestWrapper(cmd *cobra.Command, args []string, w io.Writer, archChec if err != nil { return nil, err } - extraArtifacts, err := cmd.Flags().GetStringArray("extra-artifacts") + withSBOM, err := cmd.Flags().GetBool("with-sbom") if err != nil { return nil, err } @@ -134,6 +133,12 @@ func cmdManifestWrapper(cmd *cobra.Command, args []string, w io.Writer, archChec } } + var extraArtifacts []string + + if withSBOM { + extraArtifacts = append(extraArtifacts, "sbom") + } + opts := &manifestOptions{ OutputDir: outputDir, BlueprintPath: blueprintPath, @@ -159,7 +164,8 @@ func cmdBuild(cmd *cobra.Command, args []string) error { if err != nil { return err } - extraArtifacts, err := cmd.Flags().GetStringArray("extra-artifacts") + + withManifest, err := cmd.Flags().GetBool("with-manifest") if err != nil { return err } @@ -179,7 +185,7 @@ func cmdBuild(cmd *cobra.Command, args []string) error { buildOpts := &buildOptions{ OutputDir: outputDir, StoreDir: cacheDir, - WriteManifest: slices.Contains(extraArtifacts, "manifest"), + WriteManifest: withManifest, } return buildImage(res, mf.Bytes(), buildOpts) } @@ -201,7 +207,6 @@ operating sytsems like centos and RHEL with easy customizations support.`, } rootCmd.PersistentFlags().String("datadir", "", `Override the default data direcotry for e.g. custom repositories/*.json data`) rootCmd.PersistentFlags().String("output-dir", "", `Put output into the specified direcotry`) - rootCmd.PersistentFlags().StringArray("extra-artifacts", nil, `Export extra artifacts to the output dir (supported: "sbom","manifest", can be given multiple times)`) rootCmd.SetOut(osStdout) rootCmd.SetErr(osStderr) @@ -231,6 +236,7 @@ operating sytsems like centos and RHEL with easy customizations support.`, manifestCmd.Flags().String("ostree-parent", "", `OSTREE parent`) manifestCmd.Flags().String("ostree-url", "", `OSTREE url`) manifestCmd.Flags().Bool("use-librepo", true, `use librepo to download packages (disable if you use old versions of osbuild)`) + manifestCmd.Flags().Bool("with-sbom", false, `export SPDX SBOM document`) rootCmd.AddCommand(manifestCmd) buildCmd := &cobra.Command{ @@ -241,6 +247,7 @@ operating sytsems like centos and RHEL with easy customizations support.`, Args: cobra.ExactArgs(1), } buildCmd.Flags().AddFlagSet(manifestCmd.Flags()) + buildCmd.Flags().Bool("with-manifest", false, `export osbuild manifest`) // XXX: add --rpmmd cache too and put under /var/cache/image-builder/dnf buildCmd.Flags().String("cache", "/var/cache/image-builder/store", `osbuild directory to cache intermediate build artifacts"`) rootCmd.AddCommand(buildCmd) diff --git a/cmd/image-builder/main_test.go b/cmd/image-builder/main_test.go index 2b684ad..d9112d2 100644 --- a/cmd/image-builder/main_test.go +++ b/cmd/image-builder/main_test.go @@ -411,7 +411,7 @@ func TestBuildIntegrationExtraArtifactsManifest(t *testing.T) { "qcow2", "--distro", "centos-9", "--cache", outputDir, - "--extra-artifacts", "manifest", + "--with-manifest", "--output-dir", outputDir, }) defer restore() @@ -488,7 +488,7 @@ func TestManifestIntegrationExtraArtifactsSBOMWithOutputDir(t *testing.T) { "--arch=x86_64", "--distro=centos-9", fmt.Sprintf("--blueprint=%s", makeTestBlueprint(t, testBlueprint)), - "--extra-artifacts=sbom", + "--with-sbom", "--output-dir", outputDir, }) defer restore()