Phoenix On A Raspberry Pi with Exrm

March 30, 2016

Reading time ~2 minutes

Intro

Before you read this be sure to look at:

  1. Phoenix Advanced Deployment
  2. Exrm Docs

And if you really have a ton of time learn ye some Erlang

Deploying your Elixir App onto ARM-Linux device with Exrm

I had a Raspberry Pi 1 running OSMC on my local network for quite a while now and I trust I should be able to host my Phoenix application on that box as well. In Erlang land you need a release to run your app on a remote host. Elixir has Exrm lib for building releases for mix projects. Phoenix Docs describe deploy process thoroughly but it works for systems with Erlang pre-installed. You are on your own if you want to cross-compile your release from Intel to ARM architecture.

I failed to do build it manually on OSX so I’ve used erlang-minimal with help of Erlang Embedded docs. This post this post goes over details on how to get minimal runtime up and running.

In essence, you must have a working elrang runtime environment to get your app working, then OpenSSL lib must be present to be able to deal with crypto.

After the installation run, you will get the erlang build installed in /usr/lib/erlang/ next copy that folder to a convenient location /Volumes/Disk/erlang

That folder can be used for all further deploys to most ARM architectures.

Then tell Exrm about specific libs before running release. Libs and erts of Erlang built for Pi (/Volumes/Disk/erlang see Configure relx).

These are the steps:

Generate a new Application

$ mix help phoenix.new --no-brunch

Check if it works locally

$ cd pi
$ mix phoenix.server

Install exrm

# in mix.exs

defp deps do
  [ ..., {:exrm, "~> 1.0.3"}]
end
$ mix deps.get

Configure relx

$ mkdir -p rel
$ echo '{include_erts, "/Volumes/Disk/erlang"}.' >> rel/relx.config
$ echo '{system_libs, "/Volumes/Disk/erlang/lib"}.' >> rel/relx.config

Replace /Volumes/Disk/erlang with a path to the erts extracted from the pi

Compile the app for prod and build a release

$ MIX_ENV=prod mix phoenix.digest &&\
  MIX_ENV=prod mix compile &&\
  MIX_ENV=prod mix release

Test it:

$ scp rel/pi/releases/0.0.1/pi.tar.gz tv:~
$ ssh tv
$ cd ~ && mkdir -p app && tar -xzf pi.tar.gz -C ./app

For details see Phoenix on Pi repo

Wait in generator functions or how to mock a request in ES6

Testing requests with generator functions ES6 styleI was implementing an async retrier while refactoring some callback hell.And while tes...… Continue reading

XhrHttpRequest Webworker from the function

Published on December 20, 2015