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

Platform 0.13: look for build Dockerfiles in <layers>/generated/<buildpack-id>/Dockerfile.build #2145

Merged
merged 3 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,10 +892,21 @@ func (l *LifecycleExecution) hasExtensionsForBuild() bool {
}
// the directory is <layers>/generated/build inside the build container, but `CopyOutTo` only copies the directory
fis, err := os.ReadDir(filepath.Join(l.tmpDir, "build"))
if err == nil && len(fis) > 0 {
natalieparellano marked this conversation as resolved.
Show resolved Hide resolved
return true
}
// on newer platforms, we need to find a file such as <layers>/generated/<buildpack-id>/Dockerfile.build
fis, err = os.ReadDir(l.tmpDir)
if err != nil {
l.logger.Warnf("failed to read generated directory, assuming no build image extensions: %s", err)
return false
}
return len(fis) > 0
for _, fi := range fis {
if _, err := os.Stat(filepath.Join(l.tmpDir, fi.Name(), "Dockerfile.build")); err == nil {
return true
}
}
return false
}

func (l *LifecycleExecution) hasExtensionsForRun() bool {
Expand Down
45 changes: 38 additions & 7 deletions internal/build/lifecycle_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {

// construct fixtures for extensions
if extensionsForBuild {
// the directory is <layers>/generated/build inside the build container, but `CopyOutTo` only copies the directory
err = os.MkdirAll(filepath.Join(tmpDir, "build"), 0755)
h.AssertNil(t, err)
_, err = os.Create(filepath.Join(tmpDir, "build", "some-dockerfile"))
h.AssertNil(t, err)
if platformAPI.LessThan("0.13") {
// the directory is <layers>/generated/build inside the build container, but `CopyOutTo` only copies the directory
err = os.MkdirAll(filepath.Join(tmpDir, "build", "some-buildpack-id"), 0755)
h.AssertNil(t, err)
} else {
// the directory is <layers>/generated/some-buildpack-id inside the build container, but `CopyOutTo` only copies the directory
err = os.MkdirAll(filepath.Join(tmpDir, "some-buildpack-id"), 0755)
h.AssertNil(t, err)
_, err = os.Create(filepath.Join(tmpDir, "some-buildpack-id", "Dockerfile.build"))
h.AssertNil(t, err)
}
}
amd := files.Analyzed{RunImage: &files.RunImage{
Extend: false,
Expand Down Expand Up @@ -579,7 +585,32 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
providedOrderExt = dist.Order{dist.OrderEntry{Group: []dist.ModuleRef{ /* don't care */ }}}

when("for build", func() {
when("present <layers>/generated/build", func() {
when("present in <layers>/generated/<buildpack-id>", func() {
extensionsForBuild = true

when("platform >= 0.13", func() {
platformAPI = api.MustParse("0.13")

it("runs the extender (build)", func() {
err := lifecycle.Run(context.Background(), func(execution *build.LifecycleExecution) build.PhaseFactory {
return fakePhaseFactory
})
h.AssertNil(t, err)

h.AssertEq(t, len(fakePhaseFactory.NewCalledWithProvider), 5)

var found bool
for _, entry := range fakePhaseFactory.NewCalledWithProvider {
if entry.Name() == "extender" {
found = true
}
}
h.AssertEq(t, found, true)
})
})
})

when("present in <layers>/generated/build", func() {
extensionsForBuild = true

when("platform < 0.10", func() {
Expand All @@ -603,7 +634,7 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
})
})

when("platform >= 0.10", func() {
when("platform 0.10 to 0.12", func() {
platformAPI = api.MustParse("0.10")

it("runs the extender (build)", func() {
Expand Down
3 changes: 2 additions & 1 deletion internal/build/lifecycle_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
api.MustParse("0.10"),
api.MustParse("0.11"),
api.MustParse("0.12"),
api.MustParse("0.13"),
}
)

Expand Down Expand Up @@ -71,7 +72,7 @@ type LifecycleOptions struct {
Builder Builder
BuilderImage string // differs from Builder.Name() and Builder.Image().Name() in that it includes the registry context
LifecycleImage string
LifecycleApis []string // optional - populated only if custom lifecycle image is downloaded, from that lifecycle's container's Labels.
LifecycleApis []string // optional - populated only if custom lifecycle image is downloaded, from that lifecycle image's labels.
RunImage string
FetchRunImageWithLifecycleLayer func(name string) (string, error)
ProjectMetadata files.ProjectMetadata
Expand Down
Loading