Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pmlopes/openfaas-vertx-native-template
A Vert.x serverless template for native functions
https://github.com/pmlopes/openfaas-vertx-native-template
graalvm native-image openfaas serverless vertx
Last synced: 5 days ago
JSON representation
A Vert.x serverless template for native functions
- Host: GitHub
- URL: https://github.com/pmlopes/openfaas-vertx-native-template
- Owner: pmlopes
- License: apache-2.0
- Created: 2019-03-08T12:39:55.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-07-10T13:28:56.000Z (over 5 years ago)
- Last Synced: 2024-10-30T12:07:14.084Z (about 2 months ago)
- Topics: graalvm, native-image, openfaas, serverless, vertx
- Language: Java
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Template: openfaas-svm-template
The GraalVM SVM (Eclipse Vert.x native image) template uses maven as a build system.
The template makes use of the OpenFaaS incubator project [of-watchdog](https://github.com/openfaas-incubator/of-watchdog).
### Structure
This a template showcasing the use of GraalVM/SubstrateVM and Eclipse Vert.x as a viable runtime for Serverless functions.
Functions are pure java `xyz.jetdrone.openfaas.vertx.OpenFaaS` implementations. The minimal function can be:
```java
import io.vertx.ext.web.RoutingContext;
import xyz.jetdrone.openfaas.vertx.OpenFaaS;public class MyFunction implements Lambda {
@Override
public void handle(RoutingContext ctx) {
ctx.response().end("Hi!");
}
}
```The provided entrypoint will setup the required HTTP server and will handle all the upload parsing making it available on the
`RoutingContext` of the function.### Trying the template
```
$ faas template pull https://github.com/pmlopes/openfaas-vertx-native-template
$ faas new --lang vertx-native
```### Building
When working in development mode, the java application is build as usual:
```
mvn clean package
```When going to OpenFAAS, the build is run inside a Docker container using the provided `Dockerfile`.
The Dockerfile performs the following actions:
1. Builds the Java code
2. Generates a native image from the fat jar
3. Creates a new image and install OpenFAAS of-watchdog
4. Copies the native image to the new container
5. Configures the watchdogYou can also run the Dockerfile locally:
```
docker build -t my-vertx-fn .
docker run --rm -p 8080:8080 my-vertx-fn
```You can observe instant startup times and low memory usage:
```
Forking - vertx-fn []
2018/09/06 17:54:31 Started logging stderr from function.
2018/09/06 17:54:31 OperationalMode: http
2018/09/06 17:54:31 Started logging stdout from function.
2018/09/06 17:54:31 Writing lock file at: /tmp/.lock
2018/09/06 17:54:31 stdout: OpenFaaS Vert.x listening on port: 8000
``````
docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
cbcb653158fe priceless_volhard 0.70% 5.812MiB / 15.55GiB 0.05% 3.09kB / 0B 0B / 0B 10
```Remember that the memory usage in this case accounts for both the vert.x application and the watchdog!