https://github.com/usommerl/graalnative4s
Employ Scala for serverless applications
https://github.com/usommerl/graalnative4s
cats cats-effect circe ciris cloud-run graal graal-native graalvm graalvm-native-image http4s odin scala serverless tapir upx
Last synced: 6 days ago
JSON representation
Employ Scala for serverless applications
- Host: GitHub
- URL: https://github.com/usommerl/graalnative4s
- Owner: usommerl
- License: apache-2.0
- Created: 2020-10-09T15:50:34.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2026-01-14T01:19:23.000Z (12 days ago)
- Last Synced: 2026-01-14T05:06:24.726Z (12 days ago)
- Topics: cats, cats-effect, circe, ciris, cloud-run, graal, graal-native, graalvm, graalvm-native-image, http4s, odin, scala, serverless, tapir, upx
- Language: Scala
- Homepage: https://graalnative4s.usommerl.dev
- Size: 1.04 MB
- Stars: 69
- Watchers: 5
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# graalnative4s

[](https://codecov.io/gh/usommerl/graalnative4s)
[](https://scala-steward.org)
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][http4s] for general server functionality, [circe][circe] for JSON processing, [ciris][ciris] to load runtime configuration, [tapir][tapir] to describe HTTP endpoints and [odin][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][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.](./benchmark/upx.md)
Example: `export UPX_COMPRESSION="--best"; sbt docker`
### Deploy
This repository contains a [workflow][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.
[](https://deploy.cloud.run)
### Try
The most recent version of this small example is online here: [https://graalnative4s.usommerl.dev](https://graalnative4s.usommerl.dev)
### Acknowledgements & Participation
I have taken a lot of inspiration and knowledge from [this blog post by James Ward][inspiration]. You should check out his [hello-uzhttp][uzhttp] example. Another project that helped me to connect the dots regarding `native-image` configuration was [vasilmkd/docker-stats-monitor][docker-stats-monitor]. Suggestions and contributions to this repository are welcome!
[http4s]: https://github.com/http4s/http4s
[circe]: https://github.com/circe/circe
[tapir]: https://github.com/softwaremill/tapir
[odin]: https://github.com/valskalla/odin
[ciris]: https://github.com/vlovgr/ciris
[image]: https://github.com/users/usommerl/packages/container/package/graalnative4s
[workflow]: https://github.com/usommerl/graalnative4s/blob/deploy-gcp/.github/workflows/deploy.yaml
[inspiration]: https://jamesward.com/2020/05/07/graalvm-native-image-tips-tricks/
[uzhttp]: https://github.com/jamesward/hello-uzhttp
[docker-stats-monitor]: https://github.com/vasilmkd/docker-stats-monitor