πŸ“πŸ° Running Server Side Swift on RaspberryPi

Running Swift server applications in a huge datacenter? That is for noobs. Running Swift server applications on a Raspberry Pi, that is 1337! And now you can …

β€œModern servers often have more than 128GB of memory!”

Ha! Modern servers often have less than 1GB of memory and often consume less than 3W of power. You know:

vs.


Run Apache with mod_swift on a Raspberry Pi

It is easy to run mod_swift and ApacheExpress on a Raspi. This, and all the other demos, including mod_dbd database access and the TodoMVC backend:

… all on a Raspberry.

Raspi

You got no Raspberry Pi? Get one! It can host all the servers you need at home and it is just ~$40. I host my music library for the Sonos speakers on it, some home automation stuff, including Graphite, etc. A Raspi 3 is plenty fast. Best of all: you can run Swift on it!

Docker

Since it makes everything easier, we assume you have Docker running on your Raspi (and your Mac). Here is a how-to that describes how to setup a Docker base image:

And since your are using Swift, you are most likely using a Mac as your desktop machine, hence this will be handy:

Also get Docker for Mac of course.

Run the demo

Simple, don’t forget to map the ports:

docker run --name mod_swift -d -p 8042:8042 \
           modswift/rpi-mod_swift-demo

And just invoke:

http://IPofYourRaspi:8042/

To play with the TodoMVC stuff, you need to invoke the web interface manually (the embedded links direct the frontend to localhost):

http://todobackend.com/client/index.html?http://IPofYourRaspi:8042/todomvc/

Cows

This is all nice, but does it come with any cows? Fear not, yes, the cows module and an Express demo rendering 400+ cows are included. So is leftpad.

         (__)
       /   @@      ______
      |  /\_|     |      \
      |  |___     |       |
      |   ---@    |_______|
      |  |   ----   |    |
      |  |_____
*____/|________|
CompuCow After an All-niter

QEmu

Some well informed may ask: Do I even need a Raspi to try that? Docker-for-Mac includes QEmu support and can directly run Raspi images! That is indeed true.

Unfortunately QEmu doesn’t seem to emulate everything required for Swift, so neither Swift Package Manager nor this stuff work in QEmu (Unsupported syscall: 389).

Summary

Hey, we love feedback. Join the mailing list, Slack channel or just drop us an email to tell us why this is crap (or not?): Slack.

Written on April 21, 2017