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/ruby \ --api 0.5 \ --path ruby-buildpack \ --version 0.0.1 \ --stacks io.buildpacks.samples.stacks.bionic
This command will create
ruby-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.
--stacksStack(s) this buildpack will be compatible with. Repeat for each stack in order, or supply once by comma-separated list
-V, --versionthe version of the buildpack in buildpack.toml
You will have
buildpack.toml in your buildpack directory to describe our buildpack.
# Buildpack API version api = "0.5" # Buildpack ID and metadata [buildpack] id = "examples/ruby" version = "0.0.1" # Stacks that the buildpack will work with [[stacks]] id = "io.buildpacks.samples.stacks.bionic"
You will notice two specific fields in the file:
stack.id. The buildpack ID is the way you will reference the buildpack when you create buildpack groups, builders, etc. The stack ID is the root file system in which the buildpack will be run. This example can be run on one of two different stacks, both based upon Ubuntu Bionic.
Next, we will cover the
build scripts. These files are created in
bin directory in your buildpack directory.
Now update your
ruby-buildpack/bin/detect file and copy in the following contents:
#!/usr/bin/env bash set -eo pipefail exit 1
Also update your
ruby-buildpack/bin/build file and copy in the following contents:
#!/usr/bin/env bash set -eo pipefail echo "---> Ruby 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:bionic
Then run the following
pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-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 [detector] err: email@example.com (1) [detector] ERROR: No buildpack groups passed detection. [detector] ERROR: failed to detect: buildpack(s) failed with err