Skip to content

Commit

Permalink
Remove deprecated buildpack APIs (#1148)
Browse files Browse the repository at this point in the history
* Remove buildpack APIs 0.2-0.6 according to https://github.com/buildpacks/rfcs/blob/main/text/0110-deprecate-apis.md

- Fix acceptance by updating fixtures to use newer Buildpack API version

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Remove backwards compatible glue for buildpacks missing API version

Signed-off-by: Natalie Arellano <narellano@vmware.com>

---------

Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano authored Aug 23, 2023
1 parent 325676e commit a12fbff
Show file tree
Hide file tree
Showing 70 changed files with 520 additions and 1,564 deletions.
20 changes: 10 additions & 10 deletions acceptance/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
// check builder metadata.toml for success test
_, md := getBuilderMetadata(t, filepath.Join(copyDir, "layers", "config", "metadata.toml"))

h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.1")
})
Expand All @@ -152,7 +152,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {

// prevent regression of inline table serialization
h.AssertStringDoesNotContain(t, contents, "processes =")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.1")
h.AssertEq(t, len(md.Processes), 1)
Expand All @@ -161,7 +161,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, md.Processes[0].Command.Entries[0], "echo world")
h.AssertEq(t, len(md.Processes[0].Args), 1)
h.AssertEq(t, md.Processes[0].Args[0], "arg1")
h.AssertEq(t, md.Processes[0].Direct, false)
h.AssertEq(t, md.Processes[0].Direct, true)
h.AssertEq(t, md.Processes[0].WorkingDirectory, "")
h.AssertEq(t, md.Processes[0].Default, false)
})
Expand All @@ -184,7 +184,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {

// prevent regression of inline table serialization
h.AssertStringDoesNotContain(t, contents, "processes =")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.1")
h.AssertEq(t, len(md.Processes), 1)
Expand All @@ -193,7 +193,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, md.Processes[0].Command.Entries[0], "echo world")
h.AssertEq(t, len(md.Processes[0].Args), 1)
h.AssertEq(t, md.Processes[0].Args[0], "arg1")
h.AssertEq(t, md.Processes[0].Direct, false)
h.AssertEq(t, md.Processes[0].Direct, true)
h.AssertEq(t, md.Processes[0].WorkingDirectory, "")
h.AssertEq(t, md.Processes[0].Default, false)
})
Expand All @@ -216,10 +216,10 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
// check builder metadata.toml for success test
_, md := getBuilderMetadata(t, filepath.Join(copyDir, "layers", "config", "metadata.toml"))

h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.1")
h.AssertStringContains(t, md.Extensions[0].API, "0.9")
h.AssertStringContains(t, md.Extensions[0].API, "0.10")
h.AssertEq(t, md.Extensions[0].Extension, false) // this shows that `extension = true` is not redundantly printed in group.toml
h.AssertStringContains(t, md.Extensions[0].ID, "hello_world")
h.AssertStringContains(t, md.Extensions[0].Version, "0.0.1")
Expand Down Expand Up @@ -338,7 +338,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
// check builder metadata.toml for success test
_, md := getBuilderMetadata(t, filepath.Join(copyDir, "layers", "config", "metadata.toml"))

h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.1")
})
Expand Down Expand Up @@ -381,7 +381,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
)
_, md := getBuilderMetadata(t, filepath.Join(copyDir, "layers/different_layer_dir_from_env/config/metadata.toml"))

h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world_2")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.2")
})
Expand All @@ -403,7 +403,7 @@ func testBuilder(t *testing.T, when spec.G, it spec.S) {
)
_, md := getBuilderMetadata(t, filepath.Join(copyDir, "layers/different_layer_dir_from_env/config/metadata.toml"))

h.AssertStringContains(t, md.Buildpacks[0].API, "0.2")
h.AssertStringContains(t, md.Buildpacks[0].API, "0.10")
h.AssertStringContains(t, md.Buildpacks[0].ID, "hello_world_2")
h.AssertStringContains(t, md.Buildpacks[0].Version, "0.0.2")
})
Expand Down
100 changes: 37 additions & 63 deletions acceptance/launcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,28 @@ func TestLauncher(t *testing.T) {
}

func testLauncher(t *testing.T, when spec.G, it spec.S) {
when("Buildpack API >= 0.5", func() {
when("exec.d", func() {
it("executes the binaries and modifies env before running profiles", func() {
cmd := exec.Command("docker", "run", "--rm",
"--env=CNB_PLATFORM_API=0.7",
"--entrypoint=exec.d-checker"+exe,
"--env=VAR_FROM_EXEC_D=orig-val",
launchImage)

helper := "helper" + exe
execDHelper := ctrPath("/layers", execDBpDir, "some_layer/exec.d", helper)
execDCheckerHelper := ctrPath("/layers", execDBpDir, "some_layer/exec.d/exec.d-checker", helper)
workDir := ctrPath("/workspace")

expected := fmt.Sprintf("%s was executed\n", execDHelper)
expected += fmt.Sprintf("Exec.d Working Dir: %s\n", workDir)
expected += fmt.Sprintf("%s was executed\n", execDCheckerHelper)
expected += fmt.Sprintf("Exec.d Working Dir: %s\n", workDir)
expected += "sourced bp profile\n"
expected += "sourced app profile\n"
expected += "VAR_FROM_EXEC_D: orig-val:val-from-exec.d:val-from-exec.d-for-process-type-exec.d-checker"

assertOutput(t, cmd, expected)
})
when("exec.d", func() {
it("executes the binaries and modifies env before running profiles", func() {
cmd := exec.Command("docker", "run", "--rm", //nolint
"--env=CNB_PLATFORM_API=0.7",
"--entrypoint=exec.d-checker"+exe,
"--env=VAR_FROM_EXEC_D=orig-val",
launchImage)

helper := "helper" + exe
execDHelper := ctrPath("/layers", execDBpDir, "some_layer/exec.d", helper)
execDCheckerHelper := ctrPath("/layers", execDBpDir, "some_layer/exec.d/exec.d-checker", helper)
workDir := ctrPath("/workspace")

expected := fmt.Sprintf("%s was executed\n", execDHelper)
expected += fmt.Sprintf("Exec.d Working Dir: %s\n", workDir)
expected += fmt.Sprintf("%s was executed\n", execDCheckerHelper)
expected += fmt.Sprintf("Exec.d Working Dir: %s\n", workDir)
expected += "sourced bp profile\n"
expected += "sourced app profile\n"
expected += "VAR_FROM_EXEC_D: orig-val:val-from-exec.d:val-from-exec.d-for-process-type-exec.d-checker"

assertOutput(t, cmd, expected)
})
})

Expand Down Expand Up @@ -199,46 +197,22 @@ func testLauncher(t *testing.T, when spec.G, it spec.S) {
})

when("the process type has args", func() {
when("buildpack API 0.4", func() {
// buildpack API is determined by looking up the API of the process buildpack in metadata.toml

it("command and args become shell-parsed tokens in a script", func() {
var val2 string
if runtime.GOOS == "windows" {
val2 = `"val with space"` // windows values with spaces must contain quotes
} else {
val2 = "val with space"
}
cmd := exec.Command("docker", "run", "--rm",
"--env=CNB_PLATFORM_API=0.3",
"--env", "VAR1=val1",
"--env", "VAR2="+val2,
launchImage, "indirect-process-with-args",
) // #nosec G204
assertOutput(t, cmd, "'val1' 'val with space'")
})
})
// buildpack API is determined by looking up the API of the process buildpack in metadata.toml

when("buildpack API < 0.4", func() {
// buildpack API is determined by looking up the API of the process buildpack in metadata.toml

it("args become arguments to bash", func() {
h.SkipIf(t, runtime.GOOS == "windows", "scripts are unsupported on windows")
cmd := exec.Command("docker", "run", "--rm",
"--env=CNB_PLATFORM_API=0.3", launchImage, "legacy-indirect-process-with-args",
)
assertOutput(t, cmd, "'arg' 'arg with spaces'")
})

it("script must be explicitly written to accept bash args", func() {
h.SkipIf(t, runtime.GOOS == "windows", "scripts are unsupported on windows")
cmd := exec.Command("docker", "run", "--rm",
"--env=CNB_PLATFORM_API=0.3", launchImage, "legacy-indirect-process-with-incorrect-args",
)
output, err := cmd.CombinedOutput()
h.AssertNotNil(t, err)
h.AssertStringContains(t, string(output), "printf: usage: printf [-v var] format [arguments]")
})
it("command and args become shell-parsed tokens in a script", func() {
var val2 string
if runtime.GOOS == "windows" {
val2 = `"val with space"` // windows values with spaces must contain quotes
} else {
val2 = "val with space"
}
cmd := exec.Command("docker", "run", "--rm",
"--env=CNB_PLATFORM_API=0.3",
"--env", "VAR1=val1",
"--env", "VAR2="+val2,
launchImage, "indirect-process-with-args",
) // #nosec G204
assertOutput(t, cmd, "'val1' 'val with space'")
})
})

Expand Down
5 changes: 1 addition & 4 deletions acceptance/restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
})

it("does not restore cache=true layers not in cache", func() {
output := h.DockerRunAndCopy(t,
h.DockerRunAndCopy(t,
containerName,
copyDir,
"/layers",
Expand All @@ -166,9 +166,6 @@ func testRestorerFunc(platformAPI string) func(t *testing.T, when spec.G, it spe
// check uncached layer is not restored
uncachedFile := filepath.Join(copyDir, "layers", "cacher_buildpack", "uncached-layer")
h.AssertPathDoesNotExist(t, uncachedFile)

// check output to confirm why this layer was not restored from cache
h.AssertStringContains(t, string(output), "Removing \"cacher_buildpack:layer-not-in-cache\", not in cache")
})

it("does not restore unused buildpack layer data", func() {
Expand Down
2 changes: 1 addition & 1 deletion acceptance/testdata/analyzer/container/layers/group.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group]]
id = "some-buildpack-id"
version = "some-buildpack-version"
api = "0.2"
api = "0.10"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group]]
id = "some-other-buildpack-id"
version = "some-other-buildpack-version"
api = "0.3"
api = "0.10"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group]]
id = "another-buildpack-id"
version = "another-buildpack-version"
api = "0.2"
api = "0.10"
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ echo
cat > "${layers_dir}/launch.toml" << EOL
[[processes]]
type = "hello"
command = "echo world"
command = ["echo world"]
args = ["arg1"]
direct = false
EOL

echo "---> Done"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Buildpack API version
api = "0.2"
api = "0.10"

# Buildpack ID and metadata
[buildpack]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Buildpack API version
api = "0.2"
api = "0.10"

# Buildpack ID and metadata
[buildpack]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group]]
api = "0.2"
api = "0.10"
id = "hello_world"
version = "0.0.1"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group]]
api = "0.2"
api = "0.10"
id = "hello_world_2"
version = "0.0.2"
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[[group]]
api = "0.2"
api = "0.10"
id = "hello_world"
version = "0.0.1"

[[group-extensions]]
api = "0.9"
api = "0.10"
id = "hello_world"
version = "0.0.1"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Buildpack API version
api = "0.2"
api = "0.10"

# Buildpack ID and metadata
[buildpack]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[[group]]
api = "0.2"
api = "0.10"
id = "hello_world_2"
version = "0.0.2"
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
api = "0.3"
api = "0.10"

[buildpack]
id = "buildpack_for_ext"
version = "buildpack_for_ext_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
api = "0.3"
api = "0.10"

[buildpack]
id = "simple_buildpack"
version = "simple_buildpack_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
api = "0.6"
api = "0.10"

[buildpack]
id = "always_detect_buildpack"
version = "always_detect_buildpack_version"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[types]
build = false
launch = false
cache = true
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[types]
launch = true
4 changes: 2 additions & 2 deletions acceptance/testdata/exporter/container/layers/group.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[[group]]
id = "some-buildpack-id"
version = "some-buildpack-version"
api = "0.2"
api = "0.7"

[[group]]
id = "cacher_buildpack"
version = "cacher_v1"
api = "0.3"
api = "0.8"
6 changes: 3 additions & 3 deletions acceptance/testdata/launcher/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ FROM ubuntu:bionic

COPY linux/container /

RUN rm /layers/0.5_buildpack/some_layer/exec.d/exec.d-checker/.gitkeep
COPY --from=builder /go/helper /layers/0.5_buildpack/some_layer/exec.d/helper
COPY --from=builder /go/helper /layers/0.5_buildpack/some_layer/exec.d/exec.d-checker/helper
RUN rm /layers/0.9_buildpack/some_layer/exec.d/exec.d-checker/.gitkeep
COPY --from=builder /go/helper /layers/0.9_buildpack/some_layer/exec.d/helper
COPY --from=builder /go/helper /layers/0.9_buildpack/some_layer/exec.d/exec.d-checker/helper

ENV PATH="/cnb/process:/cnb/lifecycle:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Expand Down
6 changes: 3 additions & 3 deletions acceptance/testdata/launcher/Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ RUN go build -o helper.exe exec.d

COPY windows/container /

RUN mkdir c:\layers\0.6_buildpack\some_layer\exec.d\exec.d-checker
RUN copy helper.exe c:\layers\0.6_buildpack\some_layer\exec.d\helper.exe
RUN copy helper.exe c:\layers\0.6_buildpack\some_layer\exec.d\exec.d-checker\helper.exe
RUN mkdir c:\layers\0.9_buildpack\some_layer\exec.d\exec.d-checker
RUN copy helper.exe c:\layers\0.9_buildpack\some_layer\exec.d\helper.exe
RUN copy helper.exe c:\layers\0.9_buildpack\some_layer\exec.d\exec.d-checker\helper.exe

ENV PATH="c:\cnb\process;c:\cnb\lifecycle;C:\Windows\system32;C:\Windows;"

Expand Down
Loading

0 comments on commit a12fbff

Please sign in to comment.