Use Bamboo to Test Odoo on Ubuntu 14.04

Using Bamboo to Test Odoo on Ubuntu



= Foreword =

This article will walk you through the process of using [[|Atlassian Bamboo]] to test [[|Odoo]] on Ubuntu 14.04 and above.

The Odoo community typically uses [[|TravisCI]] & [[|RunBot]] to perform all unit/acceptance testing. This is an excellent workflow if you exclusively use [[|Github]] for version control. This is not the case at [[|LasLabs]], so the TravisCI workflow is rather cumbersome.

This tutorial is also slightly relevant for [[|Jenkins]], as it is also compatible with JUnit XML test reports. If you are using Jenkins, you will need to adapt the Bamboo steps slightly, but the build script will transfer almost transfer over 1:1 (aside from the environment variables).

= Security Note =

The Docker group is basically equivalent to root, which means that this setup can introduce significant security holes into your infrastructure if the proper precautions are not taken.

As always, test infrastructure should be completely isolated from production in order to limit attack surface from any exploit that may result from the many stages of development.

In order to learn more about Docker security and possible implications in your environment, take a look at the [[|Docker Security Docs]].

= Docker =

The first piece of this puzzle is [[|Docker]], which allows us to setup a semi-isolated container for testing.

Following is a brief set of instructions for installation of Docker. For a more extended walkthrough, take a look at [[|the Docker installation docs]]

# Add the Docker GPG key

{{{ lang=bash
sudo apt-key adv \
–keyserver hkp:// \
–recv-keys 58118E89F3A912897C070ADBF76221572C52609D

# Add the Docker repo to apt sources

{{{ lang=bash
RELEASE=`lsb_release –codename | cut -d ‘:’ -f2 | tr -d ‘\t’`
echo “deb ubuntu-$RELEASE main” > \

# Update package index & existing applications

{{{ lang=bash
sudo apt-get update &&
sudo apt-get upgrade -y

# Purge the old Docker repo & add a policy to pull from the correct repo

{{{ lang=bash
apt-get purge lxc-docker &&
apt-cache policy docker-engine

# Install Prerequisites

{{{ lang=bash
sudo apt-get install -y linux-image-extra-$(uname -r) &&
sudo apt-get install -y apparmor

# Install Docker

{{{ lang=bash
sudo apt-get install docker-engine

# Start Docker

{{{ lang=bash
sudo service docker start

# Verify Docker is installed correctly. downloads a test image and runs it in a container. When the container runs, it prints an informational message. Then, it exits.

{{{ lang=bash
sudo docker run hello-world

# The above command should output something similar to the below

Unable to find image ‘hello-world:latest’ locally
latest: Pulling from library/hello-world
03f4658f8b78: Pull complete
a3ed95caeb02: Pull complete
Digest: sha256:8be990ef2aeb16dbcb9271ddfe2610fa6658d13f6dfb8bc72074cc1ca36966a7
Status: Downloaded newer image for hello-world:latest

Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the “hello-world” image from the Docker Hub.
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:

For more examples and ideas, visit:

= Bamboo =

This article assumes that you already have a working Bamboo installation. Please follow the [[|install docs]] if you have not already.

== Permissions ==

# Add the Bamboo user to the Docker group. Switch `bamboo` for the user that Bamboo runs under in your environment

{{{ lang=bash
sudo usermod -a -G docker bamboo

# Restart Bamboo so that it picks up the new group permissions, and is able to use Docker

{{{ lang=bash
sudo service bamboo restart

== Travis2Docker ==

The next piece of this puzzle is created by [[|Vauxoo]], and is called [[|Travis2Docker]].

Travis2Docker will automatically create a Dockerfile and some nifty build scripts based on a `.travis.yml` file in a repository.

As mentioned in the Foreword, the primary testing strategy of Odoo is TravisCI, so nearly every Odoo repo already has a `travis.yml` file. Aside from this, the [[|Odoo Community Association]] has tailored a significant amount of scripts around the Travis build environment.

Using the Travis files that are already integrated into the repos provides us the benefit of not having to recreate our build processes, as well as guarantees consistency of builds should a module be moved into the community repos.

We will install Travis2Docker as part of the build plan in order to guarantee that we are always using the new version

== Build Plan ==

Now we need to create a build plan to run tests on our repo

# Log in to Bamboo, click Create at the top, then Create a new plan

# Fill out the form to create the plan & link it to the desired repo

# The first build task should be the `Source Code Checkout` task that is added by default. No changes need to be made to this task.

# Add a new Script Task, and name it whatever you would like. We will use this task to generate the Docker image, run the container, and run the tests.

# Add the following script to the new task:
{{{ lang=bash
# Setup virtualenv
virtualenv _venv

# Install Pip
curl –silent –show-error –retry 5 | _venv/bin/python

# Configure environment
export PATH=${}/tmp/usr/local/bin:$PATH
export PYTHONPATH=${}/tmp/usr/local/lib/python2.7/dist-packages:$PYTHONPATH

# Fix
# Note – requires libffi-dev
_venv/bin/pip install –upgrade pyopenssl ndg-httpsclient pyasn1

# Install Travis2Docker
_venv/bin/pip install –upgrade git+

# Clear the old images
rm -Rf ${}/docker

# Generate Docker Scripts
_venv/bin/travisfile2dockerfile \
${bamboo.planRepository.repositoryUrl} \
${bamboo.planRepository.branchName} \
–root-path=${}/docker \
–docker-image=”laslabs/docker-odoo-image” \
–include-cleanup \
–build-extra-args=”–no-cache” \
–exclude-after-success \
–run-extra-args=”-tP -e LANG=C.UTF-8 -v ${}/_results:/_results”

# Uncomment below for Lints tests
# cd ${}/docker/script/*/*/*/1

# Uncomment below for standard tests server – odoo/odoo
cd ${}/docker/script/*/*/*/2

# Uncomment below for OCA backports test server – OCA/OCB
# cd ${}/docker/script/*/*/*/3

# Build

# Rewrite the default options for compat with Bamboo
# sed -i ‘s/ -itP / -tP /g’ ./

# Start container and run tests

# Note that the above may need to be tailored a bit depending on the Travis file. The above is the standard organization, but it could vary. Look in `travis.yml` for the `env` section. The above example is for the following `env`:

– VERSION=”9.0″ ODOO_REPO=”odoo/odoo” TESTS=”1″ LINT_CHECK=”0″
# Add a new JUnit Parser task, which will allow Bamboo to parse the test results instead of just viewing a log. Name it whatever you would like.

# Change the results directory to `**/_results/*.xml`, and save.

# Save and run the plan – we should have green lights! Note that the first build will take an extraordinarily long time due to the initial download of the Docker image. Subsequent tests should be much quicker.

# From here, you would want to copy a new job in the same project for each of the Travis build jobs (typically 3 total). You can easily clone the existing job, then just change the docker script directory from `1` to `2` or `3`.






Leave a Reply

Your email address will not be published. Required fields are marked *