Skip to content

Commit

Permalink
Introduce BP_DIRECT_PROCESS to enable run images without shell
Browse files Browse the repository at this point in the history
  • Loading branch information
c0d1ngm0nk3y committed Sep 11, 2024
1 parent 9b2b260 commit d4e7952
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The buildpack will do the following:
* If process types are identified from both Binding _and_ file, the contents are merged into a single `Procfile`. Commands from the Binding take precedence if there are duplicate types.
* If process types are identified from environment _and_ Binding _or_ file, the contents are merged into a single `Procfile`. Commands from Binding or file take precedence if there are duplicate types, with Binding taking precedence over file.
* If the application's stack is `io.paketo.stacks.tiny` the contents of the `Procfile` must be single command with zero or more space delimited arguments. Argument values containing whitespace should be quoted. The resulting process will be executed directly and will not be parsed by the shell.
* If the application's stack is not `io.paketo.stacks.tiny` the contents of `Procfile` will be executed as a shell script.
* If the application's stack is not `io.paketo.stacks.tiny` the contents of `Procfile` will be executed as a shell script unless `BP_DIRECT_PROCESS` is set to `true`.

## Bindings

Expand Down
5 changes: 5 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ arch = "arm64"
include-files = ["LICENSE", "NOTICE", "README.md", "linux/amd64/bin/build", "linux/amd64/bin/detect", "linux/amd64/bin/main", "linux/arm64/bin/build", "linux/arm64/bin/detect", "linux/arm64/bin/main", "buildpack.toml"]
pre-package = "scripts/build.sh"

[[metadata.configurations]]
name = "BP_DIRECT_PROCESS"
default = "false"
description = "start the processes directly or with a shell"

[[stacks]]
id = "*"
2 changes: 2 additions & 0 deletions procfile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/mattn/go-shellwords"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
"github.com/paketo-buildpacks/libpak/sherpa"
)

type Build struct {
Expand Down Expand Up @@ -57,6 +58,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
process.Direct = true
} else {
process.Command = v.(string)
process.Direct = sherpa.ResolveBool("BP_DIRECT_PROCESS")
}

result.Processes = append(result.Processes, process)
Expand Down
30 changes: 30 additions & 0 deletions procfile/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
Expect(build.Build(ctx)).To(Equal(result))
})

context("given BP_DIRECT_PROCESS=true", func() {
it.Before(func() {
t.Setenv("BP_DIRECT_PROCESS", "true")
})

it("uses a process with direct=true", func() {
ctx.Plan = libcnb.BuildpackPlan{
Entries: []libcnb.BuildpackPlanEntry{
{
Name: "procfile",
Metadata: map[string]interface{}{
"test-type": "test-command",
},
},
},
}

result := libcnb.NewBuildResult()
result.Processes = append(result.Processes,
libcnb.Process{
Type: "test-type",
Command: "test-command",
Direct: true,
},
)

Expect(build.Build(ctx)).To(Equal(result))
})
})

context("given a special process name", func() {
var assertMarkedAsDefault = func(name string) {
ctx.Plan = libcnb.BuildpackPlan{
Expand Down

0 comments on commit d4e7952

Please sign in to comment.