Now we will set up the buildpack scaffolding.
Let’s create the directory where your buildpack will live:
buildpack new <id> command will create a directory named for the buildpack ID.
pack buildpack new examples/node-js \ --api 0.8 \ --path node-js-buildpack \ --version 0.0.1 \ --stacks io.buildpacks.samples.stacks.jammy
This command will create
node-js-buildpack directory which contains
-a, --apiBuildpack API compatibility of the generated buildpack
-h, --helpHelp for ’new'
--paththe location on the filesystem to generate the artifacts
--stacksStacks (deprecated) the buildpack will work with
-V, --versionthe version of the buildpack in buildpack.toml
You will have
node-js-buildpack/buildpack.toml in your buildpack directory to describe our buildpack.
# Buildpack API version api = "0.8" # Buildpack ID and metadata [buildpack] id = "examples/node-js" version = "0.0.1" # Targets the buildpack will work with [[targets]] os = "linux" # Stacks (deprecated) the buildpack will work with [[stacks]] id = "io.buildpacks.samples.stacks.jammy"
The buildpack ID is the way you will reference the buildpack when you create buildpack groups, builders, etc. Targets identifies the kind of build and run base images the buildpack will work with. The stack ID (deprecated) uniquely identifies a build and run image configuration the buildpack will work with. This example can be run on Ubuntu Jammy.
Next, we will cover the
build scripts. These files are created in
bin directory in your buildpack directory.
Now update your
node-js-buildpack/bin/detect file and copy in the following contents:
#!/usr/bin/env bash set -eo pipefail exit 1
Also update your
node-js-buildpack/bin/build file and copy in the following contents:
#!/usr/bin/env bash set -eo pipefail echo "---> NodeJS Buildpack" exit 1
These two files are executable
build scripts. You are now able to use this buildpack.
In order to test your buildpack, you will need to run the buildpack against your sample Ruby app using the
Set your default builder by running the following:
pack config default-builder cnbs/sample-builder:jammy
Tell pack to trust our default builder:
pack config trusted-builders add cnbs/sample-builder:jammy
Then run the following
pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack
pack build command takes in your Ruby sample app as the
--path argument and your buildpack as the
After running the command, you should see that it failed to detect, as the
detect script is currently written to simply error out.
===> DETECTING ... err: email@example.com (1) ... ERROR: No buildpack groups passed detection. ERROR: failed to detect: buildpack(s) failed with err