move fast and don’t break things! testing with docker, ansible and jenkins

14

Click here to load reader

Upload: mistio

Post on 10-May-2015

907 views

Category:

Internet


0 download

DESCRIPTION

How to set up your testing infrastructure using Docker, Ansible and Jenkins to run multiple tests from different environments and optimize for speed. A good example of what Continuous Integration means and how to integrate a complete test suite with Github. Jumpstart your tests by using Docker images and automate with Ansible playbooks.

TRANSCRIPT

Page 1: Move fast and don’t break things! Testing with docker, ansible and jenkins

Testing with Jenkins, Docker and Ansible

Page 2: Move fast and don’t break things! Testing with docker, ansible and jenkins

Move fast, but don’t break things

● Agile development

● Continuous Integration

● But don’t break production

● Testing, testing, testing

Page 3: Move fast and don’t break things! Testing with docker, ansible and jenkins

Goals

● Test everything after committing to master

● Test on different platforms

● Reduce testing time

● Automate and re-use

Page 4: Move fast and don’t break things! Testing with docker, ansible and jenkins

But why so many tests?

● Test the deployment of the app in a clean environment, a fresh build.

● Test the deployment in a staging environment and ensure backwards compatibility

● Test the interface against multiple browsers

Page 5: Move fast and don’t break things! Testing with docker, ansible and jenkins

Jenkins

● Mature and widely used

● Very flexible

● Easily extendable via plugins

● Github integration

Page 6: Move fast and don’t break things! Testing with docker, ansible and jenkins

Docker

● Fast and lightweight containers

● Docker images can jumpstart the process

● Dockerfiles for automation

● Docker repositories let us reuse images

Page 7: Move fast and don’t break things! Testing with docker, ansible and jenkins

Ansible

● Deployment automation

● Flexible configuration through playbooks

● Orchestration

Page 8: Move fast and don’t break things! Testing with docker, ansible and jenkins

The Process

● Jenkins responds to Github commits

● Calls Ansible to spawn our test servers

● Servers use Docker images to optimize test

speed

Page 9: Move fast and don’t break things! Testing with docker, ansible and jenkins

Dockerfile exampleFROM ubuntu:latest

MAINTAINER mist.io

RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list

RUN apt-get update

RUN mkdir MIST

RUN cd MIST && git clone https://github.com/mistio/mist.io

WORKDIR MIST/mist.io

RUN git pull

RUN virtualenv . && ./bin/pip install --upgrade setuptools

RUN ./bin/python bootstrap.py && ./bin/buildout -N

ADD ./test_config.py src/mist/io/tests/features/

ADD ./init.sh /

ENTRYPOINT ./init.sh

Page 10: Move fast and don’t break things! Testing with docker, ansible and jenkins

Dockerfile example

● FROM Chooses the base image (ubuntu/latest)

● RUN Runs the following commands.

● ADD Adds files from our host machine to the docker

image.

● ENTRYPOINT This tells docker to start with ./init.sh

script every time we run the image

Page 11: Move fast and don’t break things! Testing with docker, ansible and jenkins

Ansible hosts file

Group your servers in an ansible_hosts file:

[testservers]

testserver1 ansible_ssh_host=178.127.33.109

testserver2 ansible_ssh_host=178.253.121.93

testserver3 ansible_ssh_host=114.252.27.128[testservers:vars]

ansible_ssh_user=mister

ansible_ssh_private_key_file=~/.ssh/testkey

Page 12: Move fast and don’t break things! Testing with docker, ansible and jenkins

Define docker in playbook- name: Add Docker repository key

sudo: True

apt_key: url="https://get.docker.io/gpg"- name: Add Docker repository

sudo: True

apt_repository:

repo: 'deb http://get.docker.io/ubuntu docker main'

update_cache: yes- name: Install Docker

sudo: True

apt: pkg=lxc-docker state=present

notify: "Start Docker"

Page 13: Move fast and don’t break things! Testing with docker, ansible and jenkins

Define docker in playbook- name: Make dir for io docker files

command: mkdir -p docker/iotest- name: Copy io Dockerfiles

template:

src=templates/iotest/Dockerfile.j2 dest=docker/iotest/Dockerfile- name: Copy io init scripts

copy:

src=templates/iotest/init.sh dest=docker/iotest/init.sh- name: Build docker images for io

sudo: True

command: docker build -t mist/iotest docker/iotest

Page 14: Move fast and don’t break things! Testing with docker, ansible and jenkins

Thank you!

● Jenkins-Github integration:

https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin

● Complete code and examples:

http://blog.mist.io/post/82383668190/move-fast-and-dont-break-things-testi

ng-with

● A more advanced Ansible setup:

https://developer.rackspace.com/blog/move-fast-and-dont-break-things-test

ing-with-jenkins-ansible-and-docker/