Trading Fish The blog of Hector Castro

Using Docker to Manage Erlang Environments for Riak

Basho packages their own fork of Erlang/OTP along with Riak and Riak CS. The forks are typically an older version of a stable Erlang/OTP release with a few patches. Eventually, all patches included in the Basho fork are merged into later versions of an official Erlang/OTP release.

If you’re installing Riak and Riak CS from a package, then all of the hard work that surrounds bundling a custom version of Erlang/OTP has been taken care of for you. On the other hand, if you are installing Riak or Riak CS from source, then you may want to install the forked version of Erlang/OTP as well.

Docker

Docker gives us a nice way to setup an isolated environment for installing Erlang/OTP and Riak. More specifically, the docker-basho-otp image makes the whole process one step simpler by starting you off with an already built Basho fork of Erlang/OTP. As of this post, the latest custom build of Erlang/OTP is R16B02_basho5. This version is meant to be paired with Riak 2.0+.

First, we need to pull down the image that contains R16B02_basho5:

$ docker pull hectcastro/basho-otp

Next, we need to start a container and invoke /bin/bash:

$ docker run -t -i --rm hectcastro/basho-otp /bin/bash

Now, let’s test to make sure that the correct version of Erlang/OTP is available:

$ erl
Erlang R16B02-basho5 (erts-5.10.3) [source] [64-bit] [smp:4:4] [async-threads:10] ...

Eshell V5.10.3  (abort with ^G)
1>

(Control + C and then a for abort gets you out of this shell.)

Riak

Solid Erlang/OTP environment? Check.

Now we need to pull down the Riak 2.0 source code to build what’s referred to as a devrel. A devrel (or development release) automates the creation of 5 separate copies of Riak. After the devrel process is complete, you can start each copy of Riak and join all of the instances into a cluster.

First, let’s clone the Riak repository and checkout the latest Riak 2.0 tag (as of this post, the most recent tag is riak-2.0.0rc1):

$ git clone https://github.com/basho/riak.git
Cloning into 'riak'...
remote: Reusing existing pack: 16251, done.
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 16257 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (16257/16257), 11.90 MiB | 40.00 KiB/s, done.
Resolving deltas: 100% (10241/10241), done.
Checking connectivity... done.
$ cd riak
$ git checkout riak-2.0.0rc1
Note: checking out 'riak-2.0.0rc1'.
HEAD is now at 87b8934... Bump riak to 2.0.0rc1 for internal smoke testing

Next, let’s create the devrel (this step will take a few minutes):

$ make devrel DEVNODES=5

Almost there. The following steps will start all 5 Riak nodes and join them into a cluster:

$ cd dev
$ for node in `ls`; do $node/bin/riak start; done && \
    for n in {2..5}; do dev$n/bin/riak-admin cluster join dev1@127.0.0.1; done
Success: staged join request for 'dev2@127.0.0.1' to 'dev1@127.0.0.1'
Success: staged join request for 'dev3@127.0.0.1' to 'dev1@127.0.0.1'
Success: staged join request for 'dev4@127.0.0.1' to 'dev1@127.0.0.1'
Success: staged join request for 'dev5@127.0.0.1' to 'dev1@127.0.0.1'
$ /dev1/bin/riak-admin cluster plan
=============================== Staged Changes ================================
Action         Details(s)
-------------------------------------------------------------------------------
join           'dev2@127.0.0.1'
join           'dev3@127.0.0.1'
join           'dev4@127.0.0.1'
join           'dev5@127.0.0.1'
-------------------------------------------------------------------------------


NOTE: Applying these changes will result in 1 cluster transition

###############################################################################
                         After cluster transition 1/1
###############################################################################

================================= Membership ==================================
Status     Ring    Pending    Node
-------------------------------------------------------------------------------
valid     100.0%     20.3%    'dev1@127.0.0.1'
valid       0.0%     20.3%    'dev2@127.0.0.1'
valid       0.0%     20.3%    'dev3@127.0.0.1'
valid       0.0%     20.3%    'dev4@127.0.0.1'
valid       0.0%     18.8%    'dev5@127.0.0.1'
-------------------------------------------------------------------------------
Valid:5 / Leaving:0 / Exiting:0 / Joining:0 / Down:0

Transfers resulting from cluster changes: 51
  12 transfers from 'dev1@127.0.0.1' to 'dev5@127.0.0.1'
  13 transfers from 'dev1@127.0.0.1' to 'dev4@127.0.0.1'
  13 transfers from 'dev1@127.0.0.1' to 'dev3@127.0.0.1'
  13 transfers from 'dev1@127.0.0.1' to 'dev2@127.0.0.1'
$ /dev1/bin/riak-admin cluster commit
Cluster changes committed

And…we’re done. Say hello to your very own Riak 2.0 cluster, built on R16B02_basho5.