Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

ThomasVitale/devoxxuk-question-2

Repository files navigation

Devoxx UK - Question 2

This is question 2 of a game intended to demonstrate serverless and event-driven features on Kubernetes, using Knative and CloudEvents.

  • For more information on the game, visit this page.
  • For instructions on deploying the entire system, visit this page.

Question 2 is a Spring Boot project relying on Spring Cloud Function, Spring Native, and the CloudEvents Java SDK. The project has been initialized using the Knative func plugin.

Usage

$ http <url> player="jon-snow" sessionId="game-blahblah" counter=42

HTTP/1.1 200 OK
Content-Length: 98
Content-Type: application/json
accept-encoding: gzip, deflate
connection: keep-alive
user-agent: HTTPie/3.1.0

{
    "level": "devoxxuk-question-2",
    "levelScore": 10,
    "sessionId": "game-blahblah",
    "gameTime": "2022-04-19T11:40:46.04108"
}

Local execution

Make sure you have a Java 17 distribution installed.

You can run the application locally as follows.

./gradlew bootRun

To run the tests run the following command.

./gradlew test

The func CLI

It's recommended to set the FUNC_REGISTRY environment variable.

export FUNC_REGISTRY=<registry>/<username>
echo "export FUNC_REGISTRY=<registry>/<username>" >> ~/.bashrc

where <registry> is a container registry URI (for example, ghcr.io) and username is your account name on that registry.

Building

This command builds an OCI image for the function. By default, this will build a GraalVM native image.

func build -v

Note: If you want to disable the native build, you need to edit the func.yaml file and remove (or set to false) the following BuilderEnv variable:

buildEnvs:
  - name: BP_NATIVE_IMAGE
    value: "true"

Running

This command runs the func locally in a container using the image created above.

func run

Deploying

This command will build and deploy the function into cluster.

func deploy -v

Function invocation

For the examples below, please be sure to set the URL variable to the route of your function.

You get the route by following command.

func info

Note the value of Routes: from the output, set $URL to its value.

TIP:

If you use kn then you can set the url by:

# kn service describe <function name> and show route url
export URL=$(kn service describe $(basename $PWD) -ourl)

Then, call the function as follows.

http $URL player="jon-snow" sessionId="game-blahblah" counter=42

Cleanup

To clean the deployed function run:

func delete

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages