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

Introduce BP_DIRECT_PROCESS to enable run images without shell #247

Merged
merged 3 commits into from
Oct 7, 2024
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
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
Loading