I recently wrote a short blog post: OpenFaaS templates for the JVM and
created a set of OpenFaaS Kotlin templates. I like the idea of
using Docker images as packaging format for Serverless functions, but the image size is quite large. The
base image size is
83 MB and the
Kotlin Micronaut template image is
118 MB. But what if we could shrink the image size to
with improved startup time and reduced memory footprint?
GraalVM has a tool for creating Native Images that
can even be statically linked. I’ve created a template named
kotlin-graalvm-native that uses GraalVM for transforming a Kotlin JVM function
to a statically linked function. The template uses the classic
What’s the catch?
I’m no GraalVM expert so I point you to this blog post: Instant Netty Startup using GraalVM Native Image Generation to give you an idea of what to look out for.
But if you are careful with your dependencies and stay away from reflection then I think this could be really use full.
Do you want to give it a try?
Here’s how to deploy your first Kotlin GraalVM Native function. First make sure you have the following prerequisite:
- OpenFaaS up and running
faas-cli installed and working
First pull the template:
$ faas-cli template pull https://github.com/TheNatureOfSoftware/openfaas-templates
This will give you a template directory with four templates:
$ ls template/
kotlin-graalvm-native kotlin-gradle-mn kotlin-maven-mn kotlin-maven-spring
Create a new function using the
$ faas-cli new fn-kotlin-native --lang kotlin-graalvm-native --prefix <your-image-prefix>
… and build and deploy it:
$ faas-cli up -f fn-kotlin-native.yml
And finally invoke your Kotlin GraalVM Native function:
$ echo -n "This is awsome" | faas-cli invoke fn-kotlin-native
Hope you enjoyed this!