Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## `docker.io/paketobuildpacks/node-engine`

The Node Engine CNB provides the Node binary distribution. The buildpack
The Node Engine CNB provides the Node binary distribution. The buildpack
installs the Node binary distribution onto the `$PATH` which makes it available
for subsequent buildpacks and in the final running container. Examples of
for subsequent buildpacks and in the final running container. Examples of
buildpacks that might use the Node binary distribution are the [NPM
CNB](https://github.com/paketo-buildpacks/npm) and [Yarn Install
CNB](https://github.com/paketo-buildpacks/yarn-install)
Expand Down Expand Up @@ -148,6 +148,13 @@ the `BP_NODE_PROJECT_PATH` environment variable at build time either directly
file](https://github.com/buildpacks/spec/blob/main/extensions/project-descriptor.md).
This could be useful if your app is a part of a monorepo.

### Exclude python installation during the build process

To exclude the participation of the cpython during the build process, please use
the `BP_NODE_EXCLUDE_BUILD_PYTHON` environment variable at build time either directly (ex. `pack build my-app --env BP_NODE_EXCLUDE_BUILD_PYTHON`).

This will skip the installation of python during the build process on the build base image, by not requiring the cpython buildpack through the build plan.

### Enabling Inspector for Remote Debugging

To enable the Inspector set the `BPL_DEBUG_ENABLED` environment variable at launch time. Optionally, you can specify the `BPL_DEBUG_PORT` environment variable to use a specific port.
Expand All @@ -162,11 +169,13 @@ For more information on debugging, see [Official Documentation](https://nodejs.o
## Run Tests

To run all unit tests, run:

```
./scripts/unit.sh
```

To run all integration tests, run:

```
/scripts/integration.sh
```
15 changes: 13 additions & 2 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,21 @@ func Detect(nvmrcParser, nodeVersionParser VersionParser) packit.DetectFunc {
})
}

bpNodeExcludeBuildPython, bpNodeExcludeBuildPythonExists := os.LookupEnv("BP_NODE_EXCLUDE_BUILD_PYTHON")
excludePython := false
if bpNodeExcludeBuildPythonExists && (bpNodeExcludeBuildPython == "" || bpNodeExcludeBuildPython == "true") {
excludePython = true
}

_, pythonNotFoundErr := exec.LookPath("python")
_, python2NotFoundErr := exec.LookPath("python2")
_, python3NotFoundErr := exec.LookPath("python3")

pythonFound := (pythonNotFoundErr == nil || python2NotFoundErr == nil || python3NotFoundErr == nil)

targetOs := os.Getenv("CNB_TARGET_DISTRO_NAME")
_, pythonNotFound := exec.LookPath("python")

installPython := (targetOs != "rhel" && pythonNotFound != nil)
installPython := (targetOs != "rhel" && !pythonFound && !excludePython)
if installPython {
requirements = append(requirements, packit.BuildPlanRequirement{
Name: Cpython,
Expand Down
155 changes: 155 additions & 0 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,161 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
})
})

context("when $BP_NODE_EXCLUDE_BUILD_PYTHON is NOT set", func() {
var pathEntries string
it.Before(func() {
pathEntries = os.Getenv("PATH")
os.Setenv("PATH", "")
})

it.After(func() {
os.Setenv("PATH", pathEntries)
})
it("and python does NOT exist on the path, it includes cpython buildpack", func() {

result, err := detect(packit.DetectContext{
WorkingDir: "/working-dir",
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
},
Requires: []packit.BuildPlanRequirement{
{
Name: nodeengine.Cpython,
Metadata: nodeengine.BuildPlanMetadata{
Build: true,
Launch: false,
},
},
},
Or: []packit.BuildPlan{
{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
{Name: nodeengine.Npm},
},
Requires: []packit.BuildPlanRequirement{
{
Name: nodeengine.Cpython,
Metadata: nodeengine.BuildPlanMetadata{
Build: true,
Launch: false,
},
},
},
},
},
}))

})
})

context("when $BP_NODE_EXCLUDE_BUILD_PYTHON is NOT set", func() {

var pathEntries string
it.Before(func() {
pathEntries = os.Getenv("PATH")
os.Setenv("PATH", pathEntries+":/some/path/to/python")
})

it.After(func() {
os.Setenv("PATH", pathEntries)
})
it("and python does exists on the path, it does NOT include on the plan", func() {

result, err := detect(packit.DetectContext{
WorkingDir: "/working-dir",
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
},
Or: []packit.BuildPlan{
{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
{Name: nodeengine.Npm},
},
},
},
}))
})
})

context("when $BP_NODE_EXCLUDE_BUILD_PYTHON is set", func() {
var pathEntries string
it.Before(func() {
pathEntries = os.Getenv("PATH")
os.Setenv("BP_NODE_EXCLUDE_BUILD_PYTHON", "true")
os.Setenv("PATH", "")
})

it.After(func() {
os.Setenv("PATH", pathEntries)
os.Unsetenv("BP_NODE_EXCLUDE_BUILD_PYTHON")
})

it("and python does NOT exist on the path, it does NOT include cpython buildpack", func() {

result, err := detect(packit.DetectContext{
WorkingDir: "/working-dir",
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
},
Or: []packit.BuildPlan{
{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
{Name: nodeengine.Npm},
},
},
},
}))
})

})
context("when $BP_NODE_EXCLUDE_BUILD_PYTHON is set", func() {

var pathEntries string
it.Before(func() {
pathEntries = os.Getenv("PATH")
os.Setenv("BP_NODE_EXCLUDE_BUILD_PYTHON", "true")
os.Setenv("PATH", pathEntries+":/some/path/to/python")
})

it.After(func() {
os.Setenv("PATH", pathEntries)
os.Unsetenv("BP_NODE_EXCLUDE_BUILD_PYTHON")
})
it("and python exists on the path, it does NOT include cpython buildpack", func() {

result, err := detect(packit.DetectContext{
WorkingDir: "/working-dir",
})
Expect(err).NotTo(HaveOccurred())
Expect(result.Plan).To(Equal(packit.BuildPlan{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
},
Or: []packit.BuildPlan{
{
Provides: []packit.BuildPlanProvision{
{Name: nodeengine.Node},
{Name: nodeengine.Npm},
},
},
},
}))

})
})

context("failure cases", func() {
context("when the dir specified by BP_NODE_PROJECT_PATH does not exist", func() {
var workingDir string
Expand Down
4 changes: 3 additions & 1 deletion integration/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ func testInspector(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.Cpython.Online,
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.Processes.Online,
).
WithEnv(map[string]string{
"BP_NODE_EXCLUDE_BUILD_PYTHON": "",
}).
Execute(name, source)

Expect(err).NotTo(HaveOccurred())
Expand Down
8 changes: 4 additions & 4 deletions integration/openssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func testOpenSSL(t *testing.T, context spec.G, it spec.S) {

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(
settings.Buildpacks.Cpython.Online,
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.BuildPlan.Online,
).
WithPullPolicy("never").
WithEnv(map[string]string{
"BP_NODE_VERSION": "20.*.*",
"BP_NODE_VERSION": "20.*.*",
"BP_NODE_EXCLUDE_BUILD_PYTHON": "",
}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down Expand Up @@ -107,13 +107,13 @@ func testOpenSSL(t *testing.T, context spec.G, it spec.S) {

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(
settings.Buildpacks.Cpython.Online,
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.BuildPlan.Online,
).
WithPullPolicy("never").
WithEnv(map[string]string{
"BP_NODE_VERSION": "20.*.*",
"BP_NODE_VERSION": "20.*.*",
"BP_NODE_EXCLUDE_BUILD_PYTHON": "",
}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
6 changes: 4 additions & 2 deletions integration/optimize_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ func testOptimizeMemory(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.Cpython.Online,
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.Processes.Online,
).
WithEnv(map[string]string{"BP_NODE_OPTIMIZE_MEMORY": "true"}).
WithEnv(map[string]string{
"BP_NODE_OPTIMIZE_MEMORY": "true",
"BP_NODE_EXCLUDE_BUILD_PYTHON": "",
}).
Execute(name, source)

Expect(err).NotTo(HaveOccurred())
Expand Down
4 changes: 2 additions & 2 deletions integration/project_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func testProjectPath(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.Cpython.Online,
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.BuildPlan.Online,
).
WithEnv(map[string]string{
"BP_NODE_PROJECT_PATH": "hello_world_server",
"BP_NODE_PROJECT_PATH": "hello_world_server",
"BP_NODE_EXCLUDE_BUILD_PYTHON": "",
}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)
Expand Down
4 changes: 3 additions & 1 deletion integration/provides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ func testProvides(t *testing.T, context spec.G, it spec.S) {
image, logs, err = pack.WithNoColor().Build.
WithPullPolicy("never").
WithBuildpacks(
settings.Buildpacks.Cpython.Online,
settings.Buildpacks.NodeEngine.Online,
settings.Buildpacks.BuildPlan.Online,
).
WithEnv(map[string]string{
"BP_NODE_EXCLUDE_BUILD_PYTHON": "",
}).
Execute(name, source)
Expect(err).ToNot(HaveOccurred(), logs.String)

Expand Down
Loading
Loading