Now we will set up the buildpack scaffolding.
Let’s create the directory where your buildpack will live:
You will now need a
buildpack.toml to describe our buildpack.
ruby-buildpack/buildpack.toml file and copy the following into it:
# Buildpack API version api = "0.5" # Buildpack ID and metadata [buildpack] id = "com.examples.buildpacks.ruby" version = "0.0.1" name = "Ruby Buildpack" # 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 you will need to create the
build scripts. These files must exist in a
bin directory in your buildpack directory.
bin directory and then change to that directory.
Now create your
ruby-buildpack/bin/detect file and copy in the following contents:
#!/usr/bin/env bash set -eo pipefail exit 1
Now create your
ruby-buildpack/bin/build and copy in the following contents:
#!/usr/bin/env bash set -eo pipefail echo "---> Ruby Buildpack" exit 1
You will need to make both of these files executable, so run the following command:
chmod +x ruby-buildpack/bin/detect ruby-buildpack/bin/build
These two files are now 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: firstname.lastname@example.org (1) [detector] ERROR: No buildpack groups passed detection. [detector] ERROR: failed to detect: buildpack(s) failed with err