This is an illustrative example of how to build statically linked nim application that produce very small single exeuctables (in the order of few MBs).
This application uses Nim Language, which compiles down to C, and subsequently to a small, performant, standalone binary.
This simple web application uses the Prologue web framework
to present the table at the bottom of the page, which is data rendered from reading the
students.db
SQLite database, which has a single table "users" with 10 dummy student records.
The table is the result of querying the sqlite database on every request and rendering it as an HTML table.
In order to present this page, the following dependencies were statically linked:
- SQLite3
- PCRE
and the following nim libraries were also compiled in:
prologue
(and all it's dependencies)db_connector
markdown
The resulting standalone docker image is a mere 5.64mb all dependencies included.
$ docker image ls simplestatapp
REPOSITORY TAG IMAGE ID CREATED SIZE
simplestatapp latest 9d3dc3a9cc58 3 minutes ago 5.64MB
You can see also see the image size during this fly.io deployment.
The code for this application is at https://github.com/btbytes/simplestatapp/, and hosted on fly.io - https://simplestatapp.fly.dev/
If you are curious about all the things that get added, built, and copied, you can inspect the Dockerfile
or take a look at the actual docker build with github actions.
And without much ado, the table: