Graalnative4s
Employ Scala for serverless applications
Install / Use
/learn @usommerl/Graalnative4sREADME
graalnative4s
This is a showcase for a combination of purely functional Scala libraries that can be used with GraalVM native-image without much effort. It employs http4s for general server functionality, circe for JSON processing, ciris to load runtime configuration, tapir to describe HTTP endpoints and odin for logging. Applications that were built with native-image have beneficial properties such as a lower memory footprint and fast startup. This makes them suitable for serverless applications.
Build
Use sbt docker to build a docker image with the native image binary. You don't need to install anything besides docker and sbt, the build process downloads all required GraalVM tooling. The created image will be as minimal as possible by using a multi-stage build.
You can create an even smaller image by utilizing UPX compression. Use the UPX_COMPRESSION environment variable at build time to specify the compression level.
Please note that while this reduces the size of the image significantly it also has an impact on startup performance and memory consumption.
Example: export UPX_COMPRESSION="--best"; sbt docker
Deploy
This repository contains a workflow that will deploy the created image to Google Cloud Run. You could also use the button below to deploy it to your own GCP account.
Try
The most recent version of this small example is online here: https://graalnative4s.usommerl.dev
Acknowledgements & Participation
I have taken a lot of inspiration and knowledge from this blog post by James Ward. You should check out his hello-uzhttp example. Another project that helped me to connect the dots regarding native-image configuration was vasilmkd/docker-stats-monitor. Suggestions and contributions to this repository are welcome!
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
