The Java Function Buildpack is a Cloud Native Buildpack that provides a Spring Boot application for executing functions.
This buildpack will participate if any of the following conditions are met:
- A buildpack configuration variable
BP_FUNCTION
is explicitly set. - A file with the name
func.yaml
is detected.
The buildpack will do the following if detection passed:
- Request for a JRE to be installed
- Contributes the function invoker to a layer marked
launch
with the layer's path prepended to$CLASSPATH
- Contributes environment variables defined in
func.yaml
to thelaunch
layer - Contributes environment variables to configure the invoker if any configuration variables are defined. (Overrides anything from
func.yaml
)
Environment Variable | Description |
---|---|
$BP_FUNCTION |
Configure the function to load. If the function lives in the default package: <class> . If the function lives in their own package: <package>.<class> . Defaults to functions.Handler |
To get started you'll need to create a directory where your function will be defined.
From within this directory we require a few files to properly detect this as a Java function:
func.yaml
(optional): We use this to configure the runtime environment variables. This buildpack makes use ofenvs
andoptions
. The keysname
andruntime
are required to maintain compatibility with Knative func cli, but are not used by this buildpack. See Knative's func.yaml documentation for morefunc.yaml
information.pom.xml
orbuild.gradle
: These are used by the other Java buildpacks to compile your function.- Java package in folder
src/main/java/functions
: This is the default location your function will be detected. If you do choose to use another package to store your functions, you will need to define where your function is located with theBP_FUNCTION
configuration for the buildpack.
To compile your function with the buildpack, we've provided a builder which has all the pre-requisites ready to go. You can find it on github.
ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder
Build the function container with the Buildpack CLI
pack build <your_image_name_and_tag> --builder ghcr.io/vmware-tanzu/function-buildpacks-for-knative/functions-builder:<version> --env BP_JVM_VERSION=17
Publish it to your registry:
docker push <your_image_name_and_tag>
The Java invoker contains a readiness/liveness endpoint that can be hit at localhost:8080/actuator/health
by default. For more information, please read about the Spring Boot Actuator's Kubernetes Probes.
If you want to quickly start writing your functions, take a look at the templates/java
folder at the root of this repo.
For some inspiration, take a look at the samples/java
folder at the root of this repo.