Continuous Integration & Deployment with Erlang 18

Today’s tools and services gives you lot of power and control when it comes to setting up continuous integration and deployments. And they provide support to all popular languages, like Ruby, Python, Javascript out of the box, as well as some hip ones, like Rust and Go, that might not be used that much, but sound cool.

Our mission: Github to Heruko via CircleCI

Our mission: Github to Heruko via CircleCI

We at The Product Works for one of our latest projects utilised a well known although seldom used language, Erlang. This set us for a challenge, as we wanted to have the same nice and easy pipeline that we adopt for all our projects: we commit our changes to GitHub, they get picked up by a testing service and then they get deployed to a cloud server provider. After much searching around the interwebs, we realised that the actual task is easy, although not well documented at all.

To save the trouble for others who might have the same needs as us, we would like to present our solution here.

1. Make Builds on Circle CI

After considering many CI tools, we settled with Circle CI. Circle offers an outdated Erlang version as supported, but we wanted to avail some of the new features that v18.0 offers at the time. Fortunately, Circle offers a fully customisable configuration file (circle.yml) that we can use to install the Erlang version needed on the host container by each build. It also has other tools like Rebar to run our tests and make our builds with.

Our circle.yml does exactly this, using the makefile’s test command to run the tests and produce the artefacts we need for code quality purposes. 

# circle.yml
    PATH: ${HOME}/otp_src_18.0/bin:${PATH}
    - ".eunit/"
    - "~/otp_src_18.0"
    - "~/rebar"
    - if [ ! -d ~/otp_src_18.0 ]; then wget; tar zxvf otp_src_18.0.tar.gz -C $HOME; cd ~/otp_src_18.0 && ./configure && make && sudo make install; fi
    - if [ ! -f ~/otp_src_18.0/bin/rebar ]; then git clone git://; cd rebar && ./bootstrap; cp rebar ~/otp_src_18.0/bin/rebar; fi
    - rebar get-deps
    - rebar compile
    - make test

2. Run the Build to Heroku

The next step was the continuous deployment, where on passing the test suite, we could deploy the code automatically to a Heroku instance. First we had to change the heroku erlang buildpack to include an extra step, where we create a release out of the compiled code. Next was setting our preferred OTP version to 18.0 and then modifying our Procfile to suit our needs when running the application. Our procfile looks like this:

# Procfile

web: erl -pa $PWD/ebin $PWD/deps/*/ebin -noshell -boot start_sasl -s reloader -s app_name -config ./rel/app_name/releases/1/sy

3. Push Builds from Circle CI to Heroku

After setting this up, and creating the Heroku app, all we had to do is connect Circle CI to Heroku using the API key settings, and put this to the end of the circle.yml file:

     branch: master
       appname: app-name