An open API service indexing awesome lists of open source software.

https://github.com/thomasvitale/devoxxuk-question-4


https://github.com/thomasvitale/devoxxuk-question-4

Last synced: 7 months ago
JSON representation

Awesome Lists containing this project

README

          

# Devoxx UK - Question 4

This is question 4 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](https://github.com/salaboy/from-monolith-to-k8s/tree/main/game).
* For instructions on deploying the entire system, visit this [page](https://github.com/ThomasVitale/eventing-game).

Question 4 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](https://github.com/knative-sandbox/kn-plugin-func) plugin.

## Usage

```shell
$ http player="jon-snow" sessionId="game-blahblah" message="Spring loves Knative"

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

{
"player": "jon-snow"
"level": "devoxxuk-question-4",
"levelScore": 33,
"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.

```shell
./gradlew bootRun
```

To run the tests run the following command.

```shell
./gradlew test
```

## The `func` CLI

It's recommended to set the `FUNC_REGISTRY` environment variable.

```shell script
export FUNC_REGISTRY=/
echo "export FUNC_REGISTRY=/" >> ~/.bashrc
```

where `` 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.

```shell
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.

```shell
func run
```

### Deploying

This command will build and deploy the function into cluster.

```shell
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.

```shell script
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:

```shell script
# kn service describe and show route url
export URL=$(kn service describe $(basename $PWD) -ourl)
```

Then, call the function as follows.

```shell script
http $URL player="jon-snow" sessionId="game-blahblah" message="Spring loves Knative"
```

## Cleanup

To clean the deployed function run:

```shell
func delete
```