/ow-scf-greeter

OpenShift OpenWhisk Spring Cloud Functions Greeter Demo

Primary LanguageShellApache License 2.0Apache-2.0

OpenShift - OpenWhisk - Spring Cloud Functions

Greeter demo application shows deploying Spring Cloud Functions application to OpenWhisk deployed on OpenShift/Kubernetes.

Overview

This example shows how to build and deploy a Spring Boot Application with functions defined as Spring Beans.

Pre-requisite

Build

Build application

./mvnw clean install

Docker Build application

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 default 0.0.1-SNAPSHOT

  • SPRING_BOOT_VERSION default 1.5.9.RELEASE

  • SPRING_CLOUD_FUNCTION_VERSION default 1.0.0.BUILD-SNAPSHOT

  • JAVA_APP_NAME default com.redhat.developers.greeter.GreeterApplication

  • FUNCTION_NAME default greeter

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 .

Deploying Function to OpenWhisk

Create

wsk -i action create hello --docker kameshsampath/ow-scf-greeter

Update

wsk -i update create hello --docker kameshsampath/ow-scf-greeter

Testing Function

OpenWhisk CLI

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

REST API

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)
  1. Get the function REST url

  2. Get the credentials to invoke the action

  3. Will return a activation id e.g. {"activationId":"3fc210dc8acf47788210dc8acf277875"}

  4. Will output the result of curl call

Base Docker Images

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:

The sources of the docker images is available here

Note
Applications and bases images uses SNAPSHOT builds