This topic describes buildpacks and how they are used in PFS to build container images from source code.
When building a container image, whether it happens locally or on cluster, PFS uses Cloud Native Buildpacks.
Buildpacks are pluggable, modular tools that translate source code into OCI images. They offer a programmatic alternative to Dockerfiles for building images, enabling composition of fine grained, dedicated, pieces of logic.
The function builder used by PFS is composed of the following buildpacks, grouped by invoker language.
- OpenJDK buildpack: contributes OpenJDK JREs and JDKs.
- Build System buildpack: performs Java based builds.
- Java function buildpack: contributes the Java invoker for running Java functions.
- NodeJS buildpack: contributes node.js runtime.
- NPM buildpack: performs npm based builds.
Buildpacks rely on a two-phase contract for building images:
- The “detect” phase first determines which buildpacks will participate in the build.
- During the “build” phase, each participating buildpack can act on the results of previous buildpacks, and contribute state to the next.
This mechanism is exploited for PFS functions as follows:
- The presence of a
build.gradlefile will trigger compilation and building of an image for running a Java function.
package.jsonfile or an
--artifactflag pointing to a
--artifactflag pointing to a file with execute permissions will generate an image for running a Command function.
In addition to smart detection logic, buildpacks provide some extra benefits such as the ability to craft image layers in a way that allow intelligent caching and re-use.
When re-building a function, if some aspects of the source have not changed, then buildpacks can decide to re-use layers, thus shortening the build lifecyle.
As an example of such a mechanism, if the
Another benefit of buildpacks and their layered approach is the ability to patch images by replacing layers remotely, without impacting the behavior of the function.
This is especially important when security patches need to be applied to OS-level layers of hundreds of images at once.
More information can be found at the buildpacks.io site.