Skip to content

Instantly share code, notes, and snippets.

@trisberg
Created August 14, 2019 16:54
Show Gist options
  • Save trisberg/ecfc72230db481bcea65993e748eaf0c to your computer and use it in GitHub Desktop.
Save trisberg/ecfc72230db481bcea65993e748eaf0c to your computer and use it in GitHub Desktop.
riff 0.3.x Java Function Invoker builds

Building and deploying functions to local cluster

To build and deploy your function locally you can use the riff CLI which can be installed following the instructions on the riff Release page.

You also need to have riff and Knative installed on a local Minikube or Docker for Mac cluster, just follow the instructions we linked to.

If you are using Minikube then you should configure Docker to use the Docker environment running in Minikube:

eval $(minikube docker-env)

Now you can build and deploy your function from the base directory of your app source. You need to provide the --handler option (see above for different handler types). To build the uppercase sample Boot app that is using a function bean, use:

riff function create uppercase --handler uppercase --local-path . --image dev.local/uppercase:v1

NOTE: If your Spring Boot application contains a single function bean, then you can omit the --handler flag since the invoker is able to automatically detect it. You can also omit the --handler flag if the JAR manifest has a Function-Class entry.

NOTE: You need to provide a tag for the image to avoid Kubernetes trying to download the latest version of the image. The default pull policy is IfNotPresent which means that Kubernetes will always attempt to pull the latest image from the registry unless there is a tag specified.

Once the function is up and running you can invoke it using:

riff service invoke upper --text -- -w '\n' -d "hello world"

To delete the function use:

riff service delete upper

Building and deploying functions to remote cluster

To build and deploy your function to a remote cluster you can use the riff CLI which can be installed following the instructions on the riff Release page.

You also need to have riff and Knative installed on a Kubernetes cluster. We provide instructions for Google Cloud Platform's Kubernetes Engine (GKE)](https://projectriff.io/docs/getting-started/gke/), just follow the instructions we linked to.

Make sure that you initialize the default namespace with the JSON key file (gcr-storage-admin.json) you created during the riff installation:

riff namespace init default --gcr gcr-storage-admin.json

You need to push your function source to a Git repo and provide the URL for the command that creates the function. Here we are using a sample function from the riff samples.

Now you can build and deploy your function from this Git repo. You need to provide the --handler option (see above for different handler types). To build with a plain Java function, you can use:

export GCP_PROJECT=$(gcloud config get-value core/project)
export GIT_REPO=https://github.com/projectriff-samples/java-hello.git
riff function create hello --git-repo $GIT_REPO --handler functions.Hello --image gcr.io/$GCP_PROJECT/java-hello --verbose

NOTE: If your Spring Boot application contains a single function bean, then you can omit the --handler options since the invoker is able to automatically detect it. You can also omit the --handler if the JAR manifest has a Function-Class entry.

NOTE: It is possible to have multiple function beans in the same source repository and just refer to the one you want to use when creating the riff function using the --handler option.

Once the function is up and running you can invoke it using:

riff service invoke hello --text -- -w '\n' -d "world"

To delete the function use:

riff service delete hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment