From de6a32ed218c04218ba493f2e34968136cd969ed Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Thu, 4 Apr 2024 19:39:53 +0000 Subject: [PATCH] fix: import a bom only if available from built layers It is possible that a build_only layer doesn't generate a BOM, so it cannot be imported in a derived layer. Signed-off-by: Ramkumar Chinchani --- pkg/stacker/bom.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/stacker/bom.go b/pkg/stacker/bom.go index f1633cb4..e048db8a 100644 --- a/pkg/stacker/bom.go +++ b/pkg/stacker/bom.go @@ -3,10 +3,12 @@ package stacker import ( "fmt" "io" + "io/fs" "os" "path" "path/filepath" + "github.com/pkg/errors" "stackerbuild.io/stacker/pkg/container" "stackerbuild.io/stacker/pkg/log" "stackerbuild.io/stacker/pkg/types" @@ -109,6 +111,11 @@ func ImportArtifacts(sc types.StackerConfig, src types.ImageSource, name string) // if a bom is available, add it here so it can be merged srcpath := path.Join(sc.StackerDir, "artifacts", src.Tag, fmt.Sprintf("%s.json", src.Tag)) + _, err := os.Lstat(srcpath) + if err != nil && errors.Is(err, fs.ErrNotExist) { + return nil + } + dstfp, err := os.CreateTemp(path.Join(sc.StackerDir, "artifacts", name), fmt.Sprintf("%s-*.json", name)) if err != nil { return err