Skip to content

Commit

Permalink
Allow additional build args for pack build
Browse files Browse the repository at this point in the history
Signed-off-by: Ralf Pannemans <ralf.pannemans@sap.com>
  • Loading branch information
c0d1ngm0nk3y authored and robdimsdale committed Dec 1, 2023
1 parent 4ecd687 commit c8831be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
32 changes: 20 additions & 12 deletions pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,29 @@ type PackBuild struct {
verbose bool
noColor bool

buildpacks []string
extensions []string
network string
builder string
clearCache bool
env map[string]string
trustBuilder bool
pullPolicy string
sbomOutputDir string
volumes []string
gid string
runImage string
buildpacks []string
extensions []string
network string
builder string
clearCache bool
env map[string]string
trustBuilder bool
pullPolicy string
sbomOutputDir string
volumes []string
gid string
runImage string
additionalBuildArgs []string

// TODO: remove after deprecation period
noPull bool
}

func (pb PackBuild) WithAdditionalBuildArgs(args ...string) PackBuild {
pb.additionalBuildArgs = append(pb.additionalBuildArgs, args...)
return pb
}

func (pb PackBuild) WithRunImage(runImage string) PackBuild {
pb.runImage = runImage
return pb
Expand Down Expand Up @@ -225,6 +231,8 @@ func (pb PackBuild) Execute(name, path string) (Image, fmt.Stringer, error) {
args = append(args, "--run-image", pb.runImage)
}

args = append(args, pb.additionalBuildArgs...)

buildLogBuffer := bytes.NewBuffer(nil)
err := pb.executable.Execute(pexec.Execution{
Args: args,
Expand Down
21 changes: 21 additions & 0 deletions pack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,27 @@ func testPack(t *testing.T, context spec.G, it spec.S) {
})
})

context("when given additional build args", func() {
it("includes the additional args", func() {
image, logs, err := pack.Build.
WithAdditionalBuildArgs("--not-supported-yet", "true").
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",
"--not-supported-yet", "true",
}))
Expect(dockerImageInspectClient.ExecuteCall.Receives.Ref).To(Equal("myapp"))
})
})

context("failure cases", func() {
context("when the executable fails", func() {
it.Before(func() {
Expand Down

0 comments on commit c8831be

Please sign in to comment.