CONTINUOUS
INTEGRATION &&
DOCKER
GOING PARALLEL
byMichaelBodnarchuk @davert
WHO AM I?
Web developer with Ruby,
JavaScriptand PHP experience
Lead developer of
Space Traveler
Codeception PHP
TestingFramework
WHAT IS ALL ABOUT?
Developmentvs TestingEnvironment
UsingDocker for Testing
Overview of CI Servers
RunningParalellJobs
DEVELOPMENT
ENVIRONMENT
use same OS
use same PHP/Java/Ruby/Python version
use same services (Nginx, MySQL, Mongo)
use same configurations
setup fake smtp server
TESTING ENVIRONMENT
same as DevelopmentEnvironment
prepared to run on CI server
uses databasewithdata fixtures
should be cleaned after tests execution
maycontain additionalservices like Selenium
TESTING+DEVELOPMENT
SETUP
Use provisioning: Chef, Ansible, Puppet, ...
Create/delete databases for each testexecution
Solve isolation issues for paralleltesting
OR USE
WHAT IS DOCKER
Docker is an open platform distributed apps
Runs and manages isolated Linux containers
Provides GitHub-like infrastructure
Host
Container 1
Container 2
Container 3
Container ...
Docker Client
dockerpull
dockerrun
docker...
Docker Index
Docker Daemon
DOCKER IMAGES
Isolated Filesystem
BuiltbyDocker
Uses IncrementalFS Drivers
Can be stored in Docker Registry
IMAGES BUILT FROM DOCKERFILE
FROMfedora:20
RUN yuminstall-ymongodb-server&&yumcleanall
RUN mkdir-p/var/lib/mongodb&&
touch/var/lib/mongodb/.keep&&
chown-Rmongodb:mongodb/var/lib/mongodb
ADDmongodb.conf/etc/mongodb.conf
VOLUME["/data/db"]
EXPOSE27017
USERmongodb
WORKDIR/var/lib/mongodb
CMDmongod
DOCKER CONTAINER
Runningcontainer != bootingOS
No daemons willbe executed on start
Onlyone process can be run atonce
RUN CONTAINER$dockerrun-it-p27017:27017-v/var/www/project/data:/datamongo1
CONTINUOUS INTEGRATION (CI) IS A DEVELOPMENT
PRACTICE THAT REQUIRES DEVELOPERS TO INTEGRATE CODE
INTO A SHARED REPOSITORY SEVERAL TIMES A DAY. EACH
CHECK-IN IS THEN VERIFIED BY AN AUTOMATED BUILD,
ALLOWING TEAMS TO DETECT PROBLEMS EARLY.
thoughtworks.com/continuous-integration
TRAVIS CI
TRAVIS CI FEATURES
SaaS
Freefor opensourceprojects
Simple configuration
Virtualization viaOpenVPN/Docker
Concurrentbuilds
Plans startfrom 129$/month
JENKINS CI
JENKINS FEATURES
Free Hosted
Dozens of Plugins
The MostPopular and Trusted
Old-SchoolInterface
RUNNING PARALLEL
BUILDS
TravisCI: out-of-box. Runs same tests suites for different
language versions. I.e. PHP 5.3, 5.4, 5.5
JenkinsCI: usingmulti-configuration project(MatrixReloaded
plugin). Builds can be executed on slave servers.
BUILD MATRIX
1. Configure axis
2. Combinate values
3. Use currentvalues as environmentvars
CONFIGURATION MATRIX EXAMPLE
RUN CONCURENT JOBdockerrun-i-t-v$WORKSPACE:/projecttest_container./runtests.sh$SUITE
WHAT'S INSIDE TEST CONTAINER?
Testcontainer contain prepared database
./runtests.shstarts allrequired services (nginx, mysql,
selenium, redis, etc)
Container stops when tests are finished
No supervisors: we can execute onlyone process per run
RUNTESTS.SH
#!/bin/sh
echo"StartingServices...."
serviceelasticsearchstart>/dev/null2>&1
servicenginxstart>/dev/null2>&1
servicephp5-fpmstart>/dev/null2>&1
servicemysqlstart>/dev/null2>&1
servicememcachedstart>/dev/null2>&1
phantomjs--webdriver=4444>/dev/null2>&1&
mailcatcher-f >/dev/null2>&1&
echo"Runningtests"
cd/project/$1#switchtoapplication
codeceptrun$2#runtestsfromspecificsuite
LESSONS LEARNED
stopped containers should be removed
containers should be auto-rebuilton testdataupdates
CONCLUSIONS
Testexecution time can be improved byrunningtests in
parallel
Docker makes easyto run isolated concurrentbuilds
QUESTIONS?
Talk by
GitHub:
Projects: , ,
MichaelBodnarchuk @davert
DavertMik
Codeception Robo Task Runner JSter

CONTINUOUS INTEGRATION && DOCKER