Greeter demo application shows deploying Spring Cloud Functions application to OpenWhisk deployed on OpenShift/Kubernetes.
This example shows how to build and deploy a Spring Boot Application with functions defined as Spring Beans.
To make the builds faster and resolve to right repositories the application uses contrib/settings.xml
during
build.
Note
|
The default app is configured to use mirrors, it can be removed if you don’t use nexus |
The Docker build takes the following arguments,
-
APP_VERSION
default0.0.1-SNAPSHOT
-
SPRING_BOOT_VERSION
default1.5.9.RELEASE
-
SPRING_CLOUD_FUNCTION_VERSION
default1.0.0.BUILD-SNAPSHOT
-
JAVA_APP_NAME
defaultcom.redhat.developers.greeter.GreeterApplication
-
FUNCTION_NAME
defaultgreeter
docker-hello-app: docker build --rm \ --build-arg APP_VERSION=$(APP_VERSION) \ --build-arg SPRING_BOOT_VERSION=$(SPRING_BOOT_VERSION) \ --build-arg SPRING_CLOUD_FUNCTION_VERSION=$(SPRING_CLOUD_FUNCTION_VERSION) \ --build-arg JAVA_APP_NAME=$(JAVA_APP_NAME) \ --build-arg FUNCTION_NAME=$(FUNCTION_NAME) \ --tag kameshsampath/ow-scf-greeter .
As the function takes single parameter called name
, it is required to pass it via function parameter
name called payload
. The following snippet shows how to invoke it via OpenWhisk CLI:
wsk -i action invoke greeter -p payload spring --result
Each OpenWhisk action that is deployed can be invoked using REST API:
URL=$(wsk -i action get greeter --url | tail -n 1) (1) AUTH=$(wsk -i property get --auth | awk '{print $3}') (2) curl -k -H "Content-Type: application/json" -u "$AUTH" -d '{"payload": "openshift"}' $URL (3) wsk -i activation result [activationId from <3>] (4)
-
Get the function REST url
-
Get the credentials to invoke the action
-
Will return a activation id e.g.
{"activationId":"3fc210dc8acf47788210dc8acf277875"}
-
Will output the result of curl call
The Spring Boot applications need to build the custom docker images to run the app, the details of how to build the docker image is available here,
For convenience the following docker images are built and available to be used to run Spring Cloud Functions on OpenWhisk:
-
https://hub.docker.com/r/kameshsampath/ow-scf-base/
- this base image for all OpenWhisk and Spring Cloud Functions applications -
https://hub.docker.com/r/kameshsampath/ow-scf-app-runner/
- this image extends base image and suitable for running Spring Cloud Function Spring Boot Applications -
https://hub.docker.com/r/kameshsampath/ow-scf-fn-runner/
- this image extends base image and suitable for running Spring Cloud Function Applications as POF
The sources of the docker images is available here
Note
|
Applications and bases images uses SNAPSHOT builds |