Deploying Phoenix to Raspberry Pi 2 with Resin.IO

I was inspired by the post Using all your CPUs by Paulo A Pereira which showed a Raspberry Pi 2 running the awesome Phoenix Framework . Which got me thinking “If I had a real app running in several Raspberries, how would I manage the deployment?”

I thought Resin.io would make a great solution for this and finally I got mi Ri2 system running and deploying with a git push.

First I followed the instructions on Paulo’s post to get a raspian system with Erlang 17.5 and Elixir 1.0.4. Since Resin.io uses docker images to deploy to devices I made a docker image for Erlang and Elixir.

With my docker image ready I created an app on Resin.io, copy the image to and SD card and set up the Pi2:

Then I created a Phoenix App and added a Dockerfile to deploy the app on the Pi2 which you can find in this Github Repo

This is a normal Phoenix project with a Dockerfile with the following content:

As you can see I compile the app in the Dockerfile so that Resin can compile the project and the resulting image would be deployed to the device. This prevents the device itself from compiling the application.

After your done you should see the happy Resin unicorn.

The Pi2 starts downloading, installing and running the image …

And once its running I checked the Actions tab, check the public url checkbox and point my browser to the Resin provided url:

Success!

Performance:

The Resin provided proxy url is not a very good option to test performance so I tested it using the local network:

I didn’t get the 500 req/second that Paulo got in his test but I think its mostly because the raspberry itself is running the Resin image and on top of that, my application.

It’s also worth noting that I didn’t set up a database for the docker image so I provided the Resin app with a DATABASE_URL environment variable. Also the app itself its just serving the default Phoenix homepage.

I really enjoyed working with Resin, Phoenix and the Pi2 for this experiment. My next step will be to try a real application and see how that works in terms of deployment, performance, etc.

--

--