What’s Rich been up to? Wading through Scons and Learning Docker and using those old RPis

Well it has been a busy two weeks of hacking away. Two main things have been struggling with understanding how Scons (a kind of super make works) by wrestling with it controlling the installs of a Cmake, Bjam and Node-gyp and npm installed programs. This stuff is not easy particularly when you get 300,000 lines of debug output for ever run of the system. I learned a lot about how not to do this, but that’s another story.

Docker

What really saved my ass was Docker. Wow, what a great way to debug builds because if you have a problem, blam goes the Docker container and you can start all over in a flash. So at least things work from a known state without packages everywhere. It is the right amount of isolation compared to a gigantic 7GB VMware image, you have images that are layered with as little as 100MB worth and you can push and pull them to a repository in the sky.

Probably the best piece of advice though is that Docker is not something that you just want Google. There are so many advances happening, that you literally just want to scroll backwards through blog.docker.com to learn what is the actual correct set of instructions

Docker and the RaspberryPi recycle

The cool idea that Alex had was to dry the same thing with a stack of Raspberry Pis:

We probably have 200 of the old Raspberry Pi 1’s around and it seems a shame to waste them (Ok, I’m on a be frugal kick I guess).

  1. But lo and behold, I find that someone has been working away on just such a project and is even building Arm specific builds of Docker for RPI. There is good fortune in the world since obviously, you can’t just take an Intel x86 image and slam it onto a Raspberry Pi. Now on to see if this only works with RPI 2 or will work with RPI1. This works like a charm and in about 10 minutes, I have docker running across four Raspberry Pis! The best thing is that they are up to Debian Jessie so it is much more up to date than the old Wheezy and much more likely to run our software.
  2. You can’t use Intel x86 images but there are a few images on the hub.docker.com which are ARM or RPI. So it is fun to try them out. But they have a nice porting guide that shows how you can take Dockerfile meant for x86 and convert it to a Dockerfile meant for Raspberry Pi. It isn’t super complicated. Just switch FROM to resin/rpi-wheezy (thanks to the folks at resin.io for that!) then you look through each package and figure out if it architecture-aware and can compile on a Raspberry Pi, then run docker build and you are in business!

Docker Swarm and multiple RPis

Of course the folks at Hypriot also let you use Raspberry Pi’s in a Docker Swarm, so they act like a loosely coupled cluster. I literaly can’t wait to get all 200 of our old Pi’s into a single Docker Swarm. The instructions are pretty simple:

  1. First download their SD images, note that compared to their previous documents, the avahi or bonjour names have changes to raspberrypi and then raspberrypi-2, etc. and not pi-1, pi-2, and pi-3
  • you first ssh-copy-id root@10.x.x.x or whereever your Pi’s are. I get this by using a lan scanner and looking at the Mac Ids for the prefix b8:27.This let’s you ssh into each machine without a password. (You can get ssh-copy-id by port install openssh +ssh-copy-id)

  • After you do this you want to disable the root password (hypriot is the default) by adding Password Authentication no to sshd_config and then doing a sudo service sshd restart

  • Then you want to download Hypriot’s customized docker machine so that you can manage the individual dockers in the Raspberry Pi’s which gives you their own docker-machine with their raspberry pi driver.

  • Finally you need to create your own cluster id with this really amazing bash one liner:

  • export TOKEN=$(for i in $(seq 1 32); do echo -n $(echo "obase=16; $(($RANDOM % 16))" | bc); done; echo)

    1. Once we get the Swarm working, we can use Docker Compose to construct applications that can use the swarm then you start one machine up as the swarm master and the rest as swarm agents as usual, the magic is in one long command which says use the driver hypriot, start a swarm master using the token we just created and point it at the ip address we found and give it a name. To create the swarm agents, you just delete the –swarm-master and you are set:
    ./docker-machine create -d hypriot --swarm --swarm-master --swarm-discovery token://$TOKEN --hypriot-ip-address 192.168.1.101 pi1
    1. Use the standard Swarm with the standard port and you are set!

    In terms of fun applications how about:

    Github. Use Gogs running on the Raspberry Pi to provide git services in something needing only 5MB of Ram?

    Dokku. This is 100 lines of bash that let you run Heroku applications on your Raspberry Pi swarm

    Docker Compose. This let’s you wire various Docker containers together using various inputs and outputs.