From ac8d5f61f2bc088f759fb808d772e2c7226a11b0 Mon Sep 17 00:00:00 2001 From: Frankie Gallina-Jones Date: Thu, 10 Feb 2022 17:54:44 -0500 Subject: [PATCH] add --sbom-output-dir --- pack.go | 38 ++++++++++++++++++++++++-------------- pack_test.go | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/pack.go b/pack.go index c73a9f0..9fb2a6d 100644 --- a/pack.go +++ b/pack.go @@ -58,15 +58,16 @@ type PackBuild struct { verbose bool noColor bool - buildpacks []string - network string - builder string - clearCache bool - env map[string]string - trustBuilder bool - pullPolicy string - volumes []string - gid string + buildpacks []string + network string + builder string + clearCache bool + env map[string]string + trustBuilder bool + pullPolicy string + sbomOutputDir string + volumes []string + gid string // TODO: remove after deprecation period noPull bool @@ -97,6 +98,11 @@ func (pb PackBuild) WithEnv(env map[string]string) PackBuild { return pb } +func (pb PackBuild) WithGID(gid string) PackBuild { + pb.gid = gid + return pb +} + // Deprecated: Use WithPullPolicy("never") instead. func (pb PackBuild) WithNoPull() PackBuild { pb.noPull = true @@ -108,6 +114,11 @@ func (pb PackBuild) WithPullPolicy(pullPolicy string) PackBuild { return pb } +func (pb PackBuild) WithSBOMOutputDir(output string) PackBuild { + pb.sbomOutputDir = output + return pb +} + func (pb PackBuild) WithTrustBuilder() PackBuild { pb.trustBuilder = true return pb @@ -118,11 +129,6 @@ func (pb PackBuild) WithVolumes(volumes ...string) PackBuild { return pb } -func (pb PackBuild) WithGID(gid string) PackBuild { - pb.gid = gid - return pb -} - func (pb PackBuild) Execute(name, path string) (Image, fmt.Stringer, error) { args := []string{"build", name} @@ -173,6 +179,10 @@ func (pb PackBuild) Execute(name, path string) (Image, fmt.Stringer, error) { args = append(args, "--pull-policy", pb.pullPolicy) } + if pb.sbomOutputDir != "" { + args = append(args, "--sbom-output-dir", pb.sbomOutputDir) + } + if pb.trustBuilder { args = append(args, "--trust-builder") } diff --git a/pack_test.go b/pack_test.go index d3df37b..9d3b5e0 100644 --- a/pack_test.go +++ b/pack_test.go @@ -239,6 +239,25 @@ func testPack(t *testing.T, context spec.G, it spec.S) { }) }) + context("when given optional sbom-output-dir", func() { + it("returns an image with the given name and the build logs", func() { + image, logs, err := pack.Build.WithSBOMOutputDir("some-dir").Execute("myapp", "/some/app/path") + + Expect(err).NotTo(HaveOccurred()) + Expect(image).To(Equal(occam.Image{ + ID: "some-image-id", + })) + Expect(logs.String()).To(Equal("some stdout output\nsome stderr output\n")) + + Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{ + "build", "myapp", + "--path", "/some/app/path", + "--sbom-output-dir", "some-dir", + })) + Expect(dockerImageInspectClient.ExecuteCall.Receives.Ref).To(Equal("myapp")) + }) + }) + context("when given optional trust-builder", func() { it("returns an image with the given name and the build logs", func() { image, logs, err := pack.Build.WithTrustBuilder().Execute("myapp", "/some/app/path")