Skip to content

Commit

Permalink
add --sbom-output-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Frankie Gallina-Jones authored and ryanmoran committed Feb 11, 2022
1 parent 23547af commit ac8d5f6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
38 changes: 24 additions & 14 deletions pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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}

Expand Down Expand Up @@ -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")
}
Expand Down
19 changes: 19 additions & 0 deletions pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit ac8d5f6

Please sign in to comment.