Going tiny - A 7.7MB server image

The best things in life are small, at least when it comes to web serving. In Serve small with Fly.io and GoStatic we squeeze things down to 7.7MB for a web server, content and Fly takes care of all the https work for us.

6 Likes

This might be the smallest image so far.

Definitely, compared to our node 80mb files lol

1 Like

And I thought my 17.6mb image wasn’t too shabby. To be fair, the binary itself weight in around 15mb and does require other things like ca-certs. The gcr.io/distroless/static image works great for my needs!

1 Like

For my rust friends, I can highly recommend https://github.com/emk/rust-musl-builder

What is the best/correct way to pass command line arguments to goStatic, such as -enable-logging -enable-health?
What I have tried to add in my Dockerfile, but without success so far, also the :

CMD ./goStatic -enable-logging -enable-health
CMD ./goStatic --enable-logging --enable-health
CMD goStatic --enable-logging --enable-health
CMD [“goStatic”, “-enable-logging”. “-enable-health”]
CMD [“-enable-logging”. “-enable-health”]

This is what the logs on fly.io /apps/goStaticNN/logs show for the first CMD line above:

2022-05-12T11:42:17.347 runner[018b147] fra [info] Configuring firecracker
2022-05-12T11:42:17.450 runner[018b147] fra [info] Starting virtual machine
2022-05-12T11:42:17.718 app[018b147] fra [info] Starting init (commit: 252b7bd)…
2022-05-12T11:42:17.735 app[018b147] fra [info] Preparing to run: /goStatic /bin/sh -c ./goStatic -enable-logging -enable-health as appuser
2022-05-12T11:42:17.739 app[018b147] fra [info] 2022/05/12 11:42:17 listening on [fdaa:0:5f91:a7b:67:18b:1479:2]:22 (DNS: [fdaa::3]:53)
2022-05-12T11:42:17.777 app[018b147] fra [info] 11:42AM INF Listening at http://0.0.0.0:8043 /…

Likely, it is obvious. Thanks for any hints.

What’s wrong with the app? It seems to be working correctly from looking at the logs.

In general, tou want to set the CMD as an array and (possibly) use an entrypoint, like:

ENTRYPOINT ["./goStatic"]
CMD ["-enable-logging", "-enable-health"]

What are you expecting to happen that’s not happening?

1 Like

Great, I missed out on setting the ENTRYPOINT as well. This eliminated the redundant /goStatic /bin/sh -c ./goStatic ... above. Thank you, I could not figure out how to get rid of that.

Note however, it turns out that there must not be a leading “.” in the path to this Go binary (./goStatic leads to UnhandledIoError and CPU panic).

But with this in my Dockerfile, goStatic starts with the options:

ENTRYPOINT [“/goStatic”]
CMD [“-enable-logging”, “-enable-health”]

It writes additional logs to Fly.io, and also answers requests to the /health endpoint with 200 OK :slight_smile:

2022-05-12T12:44:45.524 runner[afb0d0eb] fra [info] Starting virtual machine
2022-05-12T12:44:45.801 app[afb0d0eb] fra [info] Starting init (commit: 252b7bd)…
2022-05-12T12:44:45.822 app[afb0d0eb] fra [info] Preparing to run: /goStatic -enable-logging -enable-health as appuser
2022-05-12T12:44:45.829 app[afb0d0eb] fra [info] 2022/05/12 12:44:45 listening on [fdaa:0:5f91:a7b:67:afb0:d0eb:2]:22 (DNS: [fdaa::3]:53)
2022-05-12T12:44:45.871 app[afb0d0eb] fra [info] 12:44PM WRN enable-logging is deprecated in favor of log-level
2022-05-12T12:44:45.871 app[afb0d0eb] fra [info] 12:44PM WRN since enable-logging is set, setting log-level to debug
2022-05-12T12:44:45.871 app[afb0d0eb] fra [info] 12:44PM DBG Logger setup… Logging Level=debug
2022-05-12T12:44:45.871 app[afb0d0eb] fra [info] 12:44PM DBG File serve path set path=/srv/http
2022-05-12T12:44:45.871 app[afb0d0eb] fra [info] 12:44PM INF Listening at http://0.0.0.0:8043 /…
2022-05-12T12:45:17.571 runner[3d1182f9] fra [info] Shutting down virtual machine
2022-05-12T12:45:17.691 app[3d1182f9] fra [info] Sending signal SIGINT to main child process w/ PID 515
2022-05-12T12:45:17.694 app[3d1182f9] fra [info] Main child exited with signal (with signal ‘SIGINT’, core dumped? false)
2022-05-12T12:45:17.695 app[3d1182f9] fra [info] Starting clean up.
2022-05-12T12:45:18.061 app[afb0d0eb] fra [info] 12:45PM DBG Request Handled Method=GET Path=/
2022-05-12T12:45:32.010 app[afb0d0eb] fra [info] 12:45PM DBG Returning Service Health
2022-05-12T12:45:32.075 app[afb0d0eb] fra [info] 12:45PM DBG Request Handled Method=GET Path=/favicon.ico

1 Like