github.com/cloudfoundry/node-engine-cnb
go get github.com/cloudfoundry/node-engine-cnb

github.com/cloudfoundry/node-engine-cnb

A Cloud Native Buildpack for Node

by paketo-buildpacks

v0.11.2 (see all)License:Apache-2.0
go get github.com/cloudfoundry/node-engine-cnb
Readme

Node Engine Cloud Native 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 buildpacks that might use the Node binary distribution are the NPM CNB and Yarn Install CNB

Integration

The Node Engine CNB provides node and npm as dependencies. Downstream buildpacks, like Yarn Install CNB or NPM CNB, can require the node dependency by generating a Build Plan TOML file that looks like the following:

[[requires]]

  # The name of the Node Engine dependency is "node". This value is considered
  # part of the public API for the buildpack and will not change without a plan
  # for deprecation.
  name = "node"

  # The version of the Node Engine dependency is not required. In the case it
  # is not specified, the buildpack will provide the default version, which can
  # be seen in the buildpack.toml file.
  # If you wish to request a specific version, the buildpack supports
  # specifying a semver constraint in the form of "15.*", "15.14.*", or even
  # "15.14.0".
  version = "15.14.0"

  # The Node Engine buildpack supports some non-required metadata options.
  [requires.metadata]

    # Setting the build flag to true will ensure that the Node Engine
    # depdendency is available on the $PATH for subsequent buildpacks during
    # their build phase. If you are writing a buildpack that needs to run Node
    # during its build process, this flag should be set to true.
    build = true

    # Setting the launch flag to true will ensure that the Node Engine
    # dependency is available on the $PATH for the running application. If you are
    # writing an application that needs to run node at runtime, this flag should
    # be set to true.
    launch = true

Or they can require both node and npm using a Build Plan that looks like the following:

[[requires]]

  # The name of the Node Engine dependency is "node". This value is considered
  # part of the public API for the buildpack and will not change without a plan
  # for deprecation.
  name = "node"

  # The version of the Node Engine dependency is not required. In the case it
  # is not specified, the buildpack will provide the default version, which can
  # be seen in the buildpack.toml file.
  # If you wish to request a specific version, the buildpack supports
  # specifying a semver constraint in the form of "15.*", "15.14.*", or even
  # "15.14.0".
  version = "15.14.0"

  # The Node Engine buildpack supports some non-required metadata options.
  [requires.metadata]

    # Setting the build flag to true will ensure that the Node Engine
    # depdendency is available on the $PATH for subsequent buildpacks during
    # their build phase. If you are writing a buildpack that needs to run Node
    # during its build process, this flag should be set to true.
    build = true

    # Setting the launch flag to true will ensure that the Node Engine
    # dependency is available on the $PATH for the running application. If you are
    # writing an application that needs to run node at runtime, this flag should
    # be set to true.
    launch = true

[[requires]]

  # The name of the Npm dependency is "npm". This value is considered
  # part of the public API for the buildpack and will not change without a plan
  # for deprecation.
  name = "npm"

Usage

To package this buildpack for consumption:

$ ./scripts/package.sh --version <version-number>

This will create a buildpackage.cnb file under the build directory which you can use to build your app as follows: pack build <app-name> -p <path-to-app> -b build/buildpackage.cnb

Configurations

Specifying a Node version

Specifying the Node version through buildpack.yml configuration will be deprecated in Node Engine Buildpack v1.0.0.

To migrate from using buildpack.yml please set the $BP_NODE_VERSION environment variable at build time either directly (ex. pack build my-app --env BP_NODE_VERSION=~15) or through a project.toml file

$BP_NODE_VERSION="~15"

This will replace the following structure in buildpack.yml:

nodejs:
  version: ~15

You can also specify a node version via an .nvmrc or .node-version file, also at the application directory root.

Enabling memory optimization

Enabling memory optimization through buildpack.yml configuration will be deprecated in Node Engine Buildpack v1.0.0.

To migrate from using buildpack.yml please set the $BP_NODE_OPTIMIZE_MEMORY environment variable at build time either directly (ex. pack build my-app --env BP_NODE_OPTIMIZE_MEMORY=true) or through a project.toml file

$BP_NODE_OPTIMIZE_MEMORY="true"

This will replace the following structure in buildpack.yml:

nodejs:
  optimize-memory: true

Specifying a project path

To specify a project subdirectory to be used as the root of the app, please use the BP_NODE_PROJECT_PATH environment variable at build time either directly (ex. pack build my-app --env BP_NODE_PROJECT_PATH=./src/my-app) or through a project.toml file. This could be useful if your app is a part of a monorepo.

Run Tests

To run all unit tests, run:

./scripts/unit.sh

To run all integration tests, run:

/scripts/integration.sh

GitHub Stars

11

LAST COMMIT

3mos ago

MAINTAINERS

0

CONTRIBUTORS

47

OPEN ISSUES

1

OPEN PRs

2
VersionTagPublished
v0.11.3-0.20211209214129-805f1a9f4d6e
5mos ago
v0.11.2
6mos ago
v0.11.2-0.20211203162115-7073a5d4b73f
6mos ago
v0.11.2-0.20211202184731-a0fa680953d8
6mos ago
No alternatives found
No tutorials found
Add a tutorial