Skip to content

Commit f0dd5e9

Browse files
pacostasjericop
andauthored
Requiring python during build time in case is not available on the build image (#1318)
* feat: requiring cpython in non rhel distros * fix: integration tests to include proeprly python * fix: offline test for cpython * Update integration/reuse_layer_rebuild_test.go remove comment --------- Co-authored-by: Jerico Pena <jericop@users.noreply.github.com>
1 parent f9b03f4 commit f0dd5e9

12 files changed

Lines changed: 71 additions & 18 deletions

constants.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package nodeengine
22

33
const (
4-
Node = "node"
5-
Npm = "npm"
4+
Node = "node"
5+
Npm = "npm"
6+
Cpython = "cpython"
67

78
DepKey = "dependency-sha"
89
BuildKey = "build"

detect.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package nodeengine
22

33
import (
44
"os"
5+
"os/exec"
56
"path/filepath"
67

78
"github.com/paketo-buildpacks/packit/v2"
@@ -16,6 +17,8 @@ type VersionParser interface {
1617
type BuildPlanMetadata struct {
1718
Version string `toml:"version"`
1819
VersionSource string `toml:"version-source"`
20+
Build bool `toml:"build"`
21+
Launch bool `toml:"launch"`
1922
}
2023

2124
func Detect(nvmrcParser, nodeVersionParser VersionParser) packit.DetectFunc {
@@ -80,6 +83,20 @@ func Detect(nvmrcParser, nodeVersionParser VersionParser) packit.DetectFunc {
8083
})
8184
}
8285

86+
targetOs := os.Getenv("CNB_TARGET_DISTRO_NAME")
87+
_, pythonNotFound := exec.LookPath("python")
88+
89+
installPython := (targetOs != "rhel" && pythonNotFound != nil)
90+
if installPython {
91+
requirements = append(requirements, packit.BuildPlanRequirement{
92+
Name: Cpython,
93+
Metadata: BuildPlanMetadata{
94+
Build: true,
95+
Launch: false,
96+
},
97+
})
98+
}
99+
83100
return packit.DetectResult{
84101
Plan: packit.BuildPlan{
85102
Provides: []packit.BuildPlanProvision{

integration.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"build-plan": "github.com/paketo-community/build-plan",
33
"builders": [
4-
"index.docker.io/paketobuildpacks/builder-jammy-buildpackless-base:latest"
5-
]
4+
"index.docker.io/paketobuildpacks/builder-jammy-buildpackless-base:latest",
5+
"index.docker.io/paketobuildpacks/ubuntu-noble-builder-buildpackless:latest"
6+
],
7+
"cpython": "github.com/paketo-buildpacks/cpython"
68
}

integration/init_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ var settings struct {
2929
Processes struct {
3030
Online string
3131
}
32+
Cpython struct {
33+
Online string
34+
Offline string
35+
}
3236
}
3337

3438
Buildpack struct {
@@ -38,6 +42,7 @@ var settings struct {
3842

3943
Config struct {
4044
BuildPlan string `json:"build-plan"`
45+
Cpython string `json:"cpython"`
4146
}
4247
}
4348

@@ -73,6 +78,15 @@ func TestIntegration(t *testing.T) {
7378
Execute(root)
7479
Expect(err).NotTo(HaveOccurred())
7580

81+
settings.Buildpacks.Cpython.Online, err = buildpackStore.Get.
82+
Execute(settings.Config.Cpython)
83+
Expect(err).ToNot(HaveOccurred())
84+
85+
settings.Buildpacks.Cpython.Offline, err = buildpackStore.Get.
86+
WithOfflineDependencies().
87+
Execute(settings.Config.Cpython)
88+
Expect(err).ToNot(HaveOccurred())
89+
7690
tmpBuildpackDir, err := os.MkdirTemp("", "node-engine-outdated-deps")
7791
Expect(err).NotTo(HaveOccurred())
7892

integration/inspector_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func testInspector(t *testing.T, context spec.G, it spec.S) {
5252
image, logs, err = pack.WithNoColor().Build.
5353
WithPullPolicy("never").
5454
WithBuildpacks(
55+
settings.Buildpacks.Cpython.Online,
5556
settings.Buildpacks.NodeEngine.Online,
5657
settings.Buildpacks.Processes.Online,
5758
).

integration/offline_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func testOffline(t *testing.T, context spec.G, it spec.S) {
5656
image, logs, err = pack.WithNoColor().Build.
5757
WithPullPolicy("never").
5858
WithBuildpacks(
59+
settings.Buildpacks.Cpython.Offline,
5960
settings.Buildpacks.NodeEngine.Offline,
6061
settings.Buildpacks.BuildPlan.Online,
6162
).

integration/openssl_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func testOpenSSL(t *testing.T, context spec.G, it spec.S) {
6767

6868
image, logs, err = pack.WithNoColor().Build.
6969
WithBuildpacks(
70+
settings.Buildpacks.Cpython.Online,
7071
settings.Buildpacks.NodeEngine.Online,
7172
settings.Buildpacks.BuildPlan.Online,
7273
).
@@ -106,6 +107,7 @@ func testOpenSSL(t *testing.T, context spec.G, it spec.S) {
106107

107108
image, logs, err = pack.WithNoColor().Build.
108109
WithBuildpacks(
110+
settings.Buildpacks.Cpython.Online,
109111
settings.Buildpacks.NodeEngine.Online,
110112
settings.Buildpacks.BuildPlan.Online,
111113
).

integration/optimize_memory_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func testOptimizeMemory(t *testing.T, context spec.G, it spec.S) {
5353
image, logs, err = pack.WithNoColor().Build.
5454
WithPullPolicy("never").
5555
WithBuildpacks(
56+
settings.Buildpacks.Cpython.Online,
5657
settings.Buildpacks.NodeEngine.Online,
5758
settings.Buildpacks.Processes.Online,
5859
).

integration/project_path_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func testProjectPath(t *testing.T, context spec.G, it spec.S) {
6060
image, logs, err = pack.WithNoColor().Build.
6161
WithPullPolicy("never").
6262
WithBuildpacks(
63+
settings.Buildpacks.Cpython.Online,
6364
settings.Buildpacks.NodeEngine.Online,
6465
settings.Buildpacks.BuildPlan.Online,
6566
).

integration/provides_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func testProvides(t *testing.T, context spec.G, it spec.S) {
5555
image, logs, err = pack.WithNoColor().Build.
5656
WithPullPolicy("never").
5757
WithBuildpacks(
58+
settings.Buildpacks.Cpython.Online,
5859
settings.Buildpacks.NodeEngine.Online,
5960
settings.Buildpacks.BuildPlan.Online,
6061
).

0 commit comments

Comments
 (0)