Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pack build --sbom-output-dir #127

Merged
merged 1 commit into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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