nodeengine

package module
v0.0.243 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

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 as a dependency. 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 "10.*", "10.15.*", or even
  # "10.15.1".
  version = "10.15.1"

  # 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

Usage

To package this buildpack for consumption:

$ ./scripts/package.sh

This builds the buildpack's Go source using GOOS=linux by default. You can supply another value as the first argument to package.sh.

buildpack.yml Configurations

In order to specify a particular version of node you can provide an optional buildpack.yml in the root of the application directory.

nodejs:
  # this allows you to specify a version constraint for the node depdendency
  # any valid semver constaints (e.g. 10.*) are also acceptable
  version: ~10

  # allow node to optimize memory usage based on your system constraints
  # bool
  optimize-memory: true

Documentation

Index

Constants

View Source
const (
	Node       = "node"
	Dependency = Node // NOTE: alias for old constant name

	DepKey             = "dependency-sha"
	NvmrcSource        = ".nvmrc"
	BuildpackYMLSource = "buildpack.yml"
)

Variables

View Source
var (
	MemoryAvailableScript = strings.TrimSpace(`
if [[ -z "$MEMORY_AVAILABLE" ]]; then
		memory_in_bytes="$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)"
		MEMORY_AVAILABLE="$(( $memory_in_bytes / ( 1024 * 1024 ) ))"
fi
export MEMORY_AVAILABLE
`)

	OptimizeMemoryScript = `export NODE_OPTIONS="--max_old_space_size=$(( $MEMORY_AVAILABLE * 75 / 100 ))"`
)

Functions

func Build

func Build(entries EntryResolver, dependencies DependencyManager, environment EnvironmentConfiguration, planRefinery BuildPlanRefinery, logger LogEmitter, clock chronos.Clock) packit.BuildFunc

func Detect

func Detect(nvmrcParser, buildpackYMLParser VersionParser) packit.DetectFunc

Types

type BuildPlanMetadata

type BuildPlanMetadata struct {
	VersionSource string `toml:"version-source"`
}

type BuildPlanRefinery

type BuildPlanRefinery interface {
	BillOfMaterial(dependency postal.Dependency) packit.BuildpackPlan
}

type BuildpackYMLParser

type BuildpackYMLParser struct{}

func NewBuildpackYMLParser

func NewBuildpackYMLParser() BuildpackYMLParser

func (BuildpackYMLParser) Parse

func (p BuildpackYMLParser) Parse(path string) (Config, error)

func (BuildpackYMLParser) ParseVersion

func (p BuildpackYMLParser) ParseVersion(path string) (string, error)

type Config

type Config struct {
	Version         string `yaml:"version"`
	OptimizedMemory bool   `yaml:"optimize-memory"`
}

type DependencyManager

type DependencyManager interface {
	Resolve(path, id, version, stack string) (postal.Dependency, error)
	Install(dependency postal.Dependency, cnbPath, layerPath string) error
}

type EntryResolver

type EntryResolver interface {
	Resolve([]packit.BuildpackPlanEntry) packit.BuildpackPlanEntry
}

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

func NewEnvironment

func NewEnvironment(logger LogEmitter) Environment

func (Environment) Configure

func (e Environment) Configure(env packit.Environment, path string, optimizeMemory bool) error

type EnvironmentConfiguration

type EnvironmentConfiguration interface {
	Configure(env packit.Environment, path string, optimizeMemory bool) error
}

type LogEmitter

type LogEmitter struct {
	// Logger is embedded and therefore delegates all of its functions to the
	// LogEmitter.
	scribe.Logger
}

func NewLogEmitter

func NewLogEmitter(output io.Writer) LogEmitter

func (LogEmitter) Candidates

func (e LogEmitter) Candidates(entries []packit.BuildpackPlanEntry)

func (LogEmitter) Environment

func (e LogEmitter) Environment(env packit.Environment, optimizeMemory bool)

func (LogEmitter) SelectedDependency

func (e LogEmitter) SelectedDependency(entry packit.BuildpackPlanEntry, dependency postal.Dependency, now time.Time)

type NvmrcParser

type NvmrcParser struct{}

func NewNvmrcParser

func NewNvmrcParser() NvmrcParser

func (NvmrcParser) ParseVersion

func (p NvmrcParser) ParseVersion(path string) (string, error)

type PlanEntryResolver

type PlanEntryResolver struct {
	// contains filtered or unexported fields
}

func NewPlanEntryResolver

func NewPlanEntryResolver(logger LogEmitter) PlanEntryResolver

func (PlanEntryResolver) Resolve

type PlanRefinery

type PlanRefinery struct{}

func NewPlanRefinery

func NewPlanRefinery() PlanRefinery

func (PlanRefinery) BillOfMaterial

func (pf PlanRefinery) BillOfMaterial(dependency postal.Dependency) packit.BuildpackPlan

type VersionParser

type VersionParser interface {
	ParseVersion(path string) (version string, err error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL