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.
I gave buildpacks another chance and discovered that they still don't work with dokku-alt and Phoenix. However dokku now supports buildpacks and dokku-alt seems somewhat unmaintained. So I switched my whole server over to dokku and now everything works like a charm.
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
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
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.