Deploying Phoenix app with dokku-alt and Dockerfile

by Andreas Knöpfle over 1 year ago
My experiences in deploying a Elixir Phoenix app on my dokku-alt instance.

After 10 hours trying to deploy a Phoenix app on my dokku-alt instance i want to share my Dockerfile. 

First I tried the deploy vie the heroku buildpack. The deployment seems to work out fine, but the app always terminates with SIGUSR1 signal. If you know why, please explain in the comments below, as I would prefer this method over the Dockerfile because it is much faster. I tried to debug this issue but didn't find the root cause, so I switched to a Dockerfile deploy. 

 

Installing Elixir and Node

First thing is to install node.js, which is used for brunch.io and Elixir/Erlang. I used an image that already has elixir installed and added node.js and some dependencies to the mix.

FROM trenpixster/elixir:1.0.4

RUN apt-get update
RUN apt-get install -y wget curl git

RUN curl -sL https://deb.nodesource.com/setup_dev | sudo bash -
RUN apt-get install -y nodejs build-essential

Add the code and env variables for dokku-alt

After adding the code to the build, i set the MIX_ENV var to production environment and expose the port 8080, so that dokku alt can route it through nginx

ADD . .

ENV MIX_ENV prod
ENV PORT 8080

EXPOSE 8080

Compiling

Installing the dependencies for elixir and node is the next step. After that, everything can be compiled. A weird thing is that the first compile command is always stuck, which gave me some headdache and cost me some hours. I fixed it by starting the command and killing it after 5 seconds, just to do it again.

RUN mix deps.get
RUN npm install
RUN (mix compile) & sleep 5 ; kill $!
RUN mix compile

Bower and assets

As i use bower and fontawesome I install bower components and copy the fontawesome fonts to the static asset folder. Bower complains when run as root , which can be prevented by a simple parameter. After that we can compile the css/js assets.

RUN node_modules/bower/bin/bower install --allow-root
RUN mkdir -p priv/static/fonts && cp bower_components/font-awesome/fonts/* priv/static/fonts
RUN node_modules/brunch/bin/brunch build --production

Run

The last thing is the run command for the server.

CMD ["mix", "phoenix.server"]

The Dockerfile is to be found here.

 

Image Source for Phoenix Logo

Back

Announcing treasures.io

Discover the internet of islands and sail through the online ocean.


asdf Version Manager & Postgres UUID

Compiling Postgres with UUID to use in asdf


Lombok Impressions

Our trip to the Indonesian island Lombok in October 2015


Moved to netcup and dokku-alt

How i moved this page to run on netcups vhosts with dokku-alt Docker instances


Capybara Sessions

How you can simulate multiple parallel users with capybara.