For continuous integration during development, we use Jenkins to automatically run tests for all projects we maintain. Some time ago we wanted to increase visibility of the results, so we set up a Raspberry Pi driving a few meters of LPD8806-based LED strip on which we can address single LEDs to represent the status of individual or aggregated builds.
Automating deployments is a good idea…
After an SD Card failure we were painfully remembered how hard it can be to set up a service where all parts were deployed manually. Fortunately we wrote at least some minimal documentation on how to set everything up, so after a few days we were presented with many broken builds. Of course nobody cared about the build status with all LEDs being dark. :(
Today we wondered if we can use our deployment-tool batou to make reproduceable deployments to a raspberry pi, and did some tests on a vanilla raspbian image (2013-07-26 “Wheezy”).
Preparing your Raspberry Pi
Of course, you can not deploy to it without some simple preparations. First thing is, batou needs to be able to log on the target host with a public ssh key, so we copied our public key to the raspi which has the address 192.168.0.5 in this example:
local> ssh-copy-id email@example.com
Type password of user pi, default: "raspberry"
(If you don’t have the ssh-copy-id, you have to manually append your ssh public key to
/home/pi/.ssh/authorized_keys, which you will need to create on a plain installation)
Manually install minimal requirements
Batou does also have a few requirements which are needed to bootstrap the environment:
- mercurial – to pull the buildout which sets up batou
- python-virtualenv – to create a clean python environment for the buildout
- python-dev – to compile libcrypto against
Note: We are currently working on batou 1.0 which most likely will no longer need any of these.
You can install all the requirements at once with the following command on your raspi:
pi> sudo aptitude install mercurial python-virtualenv python-dev
Now you are ready to do your first batou deployment to a raspberry pi. For our experiments we created a small hello-world batou deployment, containing a test component which deploys a file /tmp/test which contains “foo” to a raspberry pi specified by an IP address.
To begin, clone the repository on your local machine:
local> hg clone https://bitbucket.org/gocept/batou-on-raspberrypi
local> cd batou-on-raspberrypi
environments/pi.cfg and set the IP-address of your Raspi.
To create the nessecary scripts to do the deployment, run buildout to create a sandbox containing all dependencies of batou and the scripts you can use to deploy:
local> python bootstrap.py
After some minutes, your batou deployment sandbox will be ready for use. You most likely modified
environments/pi.cfg so you need to check in that change first, because batou refuses to deploy a dirty working copy.
local> hg ci -m 'change ip of my raspi'
To run the deployment, call batou-remote with the name of the environment (“pi”, which corresponds to
environments/pi.cfg). Because the ssh user you use to connect with the target host differs from your local user, you have to specify it with
local> bin/batou-remote pi --ssh-user=pi
Batou will now set up itself on the remote side and deploys all components specified in
pi.cfg. To show it worked, check if the deployed file contains the correct content:
pi> cat /tmp/test
To learn more about batou, check http://batou.readthedocs.org.
If you want deploy your real life mission critical python applications into a fully automated environment using batou, head over to the Flying Circus.
- Create reproducable automated deployments for your software is great fun.
- Preparing a raspi to be a target host for batou 0.2.12 based deployments is easy:
- Install python-virtualenv, mercurial and python-dev.
- Put your ssh public key on the raspi.
- Example deployment can be found on bitbucket.