Skip to content

Commit

Permalink
Merge branch 'main' into deps/jjbustamante/update-to-docker-26
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbustamante authored May 3, 2024
2 parents 2b23d38 + 57282c7 commit 2293719
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ func testAcceptance(
launchCacheVolume.Clear(context.TODO())
})

when("builder is untrusted", func() {
when("there are build image extensions", func() {
it("uses the 5 phases, and runs the extender (build)", func() {
origLifecycle := lifecycle.Image()

Expand Down
2 changes: 1 addition & 1 deletion acceptance/testdata/pack_fixtures/report_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Pack:

Default Lifecycle Version: 0.19.3

Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12
Supported Platform APIs: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13

Config:
default-builder-image = "{{ .DefaultBuilder }}"
Expand Down
21 changes: 17 additions & 4 deletions internal/build/lifecycle_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ func (l *LifecycleExecution) Detect(ctx context.Context, phaseFactory PhaseFacto
If(l.hasExtensions(), WithPostContainerRunOperations(
CopyOutToMaybe(filepath.Join(l.mountPaths.layersDir(), "analyzed.toml"), l.tmpDir))),
If(l.hasExtensions(), WithPostContainerRunOperations(
CopyOutToMaybe(filepath.Join(l.mountPaths.layersDir(), "generated", "build"), l.tmpDir))),
CopyOutToMaybe(filepath.Join(l.mountPaths.layersDir(), "generated"), l.tmpDir))),
envOp,
)

Expand Down Expand Up @@ -890,12 +890,25 @@ func (l *LifecycleExecution) hasExtensionsForBuild() bool {
if !l.hasExtensions() {
return false
}
// 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"))
generatedDir := filepath.Join(l.tmpDir, "generated")
fis, err := os.ReadDir(filepath.Join(generatedDir, "build"))
if err == nil && len(fis) > 0 {
// on older platforms, we need to find a file such as <layers>/generated/build/<buildpack-id>/Dockerfile
// on newer platforms, <layers>/generated/build doesn't exist
return true
}
// on newer platforms, we need to find a file such as <layers>/generated/<buildpack-id>/build.Dockerfile
fis, err = os.ReadDir(generatedDir)
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(generatedDir, fi.Name(), "build.Dockerfile")); err == nil {
return true
}
}
return false
}

func (l *LifecycleExecution) hasExtensionsForRun() bool {
Expand Down
43 changes: 36 additions & 7 deletions internal/build/lifecycle_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ 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") {
err = os.MkdirAll(filepath.Join(tmpDir, "generated", "build", "some-buildpack-id"), 0755)
h.AssertNil(t, err)
} else {
err = os.MkdirAll(filepath.Join(tmpDir, "generated", "some-buildpack-id"), 0755)
h.AssertNil(t, err)
_, err = os.Create(filepath.Join(tmpDir, "generated", "some-buildpack-id", "build.Dockerfile"))
h.AssertNil(t, err)
}
}
amd := files.Analyzed{RunImage: &files.RunImage{
Extend: false,
Expand Down Expand Up @@ -579,7 +583,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 +632,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 2293719

Please sign in to comment.