Skip to content

Commit

Permalink
Platform 0.13: look for build Dockerfiles in <layers>/generated/<buil…
Browse files Browse the repository at this point in the history
…dpack-id>/Dockerfile.build

Newer platforms don't copy the Dockerfile from where extensions output them

Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed Apr 29, 2024
1 parent d7c6f0e commit 78f3a7c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
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 {
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", 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

0 comments on commit 78f3a7c

Please sign in to comment.