Skip to content

Commit

Permalink
Merge pull request #247 from sap-contributions/run-without-bash
Browse files Browse the repository at this point in the history
Introduce BP_DIRECT_PROCESS to enable run images without shell
  • Loading branch information
dmikusa authored Oct 7, 2024
2 parents f12c254 + 303d850 commit 589e37c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ The buildpack will do the following:
* 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 `BP_DIRECT_PROCESS` is set to `true`, the command will not be executed within a shell.
* This behavior will become the default with the next major version, fulfilling [RFC-0093](https://github.com/buildpacks/rfcs/blob/main/text/0093-remove-shell-processes.md). Afterwards, this option will be deprecated and removed eventually.

The `BP_DIRECT_PROCESS` environment variable can be used to opt-in in starting processes directly. The next major version of this buildpack will no longer support indirect processes and all processes will be started directly. Once processes are no longer started indirectly by default, the configuration `BP_DIRECT_PROCESS` will be removed since it will have no effect.

## 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 589e37c

Please sign in to comment.