Continuous Integration at Mollie

Post on 15-Dec-2014

2.098 views 3 download

description

In this talk, I will discuss our experiences at Mollie with setting up the Jenkins Continuous Integration server for all our PHP projects. The talk will be aimed at developers with little or no experience with CI.

Transcript of Continuous Integration at Mollie

Continuous Integration for PHP

www.mollie.nl

Contents

• About Mollie

• What is CI

• What’s in it for you?

• How to set it up

• Tips

• Q&A

• Payment Service Provider

• iDEAL, Pay-per-call, Premium SMS, etc.

• SMS gateway

• HTTP API, SMPP, Email to SMS, etc.

• Located in Amsterdam, near Vondelpark

• Four developers

Codebase 1/2

• Main project: 250K LOC

• New code is pretty good, but...

• lots of code created around 2004 (when magic_quotes was cool)

Codebase 2/2

• Git as SCM

• Also:

• Plugins for OpenCart, Magento, WHCMS

• Example API classes

• Internal projects

Technology

• Nothing too complicated:

• Nginx

• PHP

• MySQL

• Redis

Continuous Integration

TheoryIn software engineering, continuous integration (CI)

implements continuous processes of applying quality control — small pieces of effort, applied frequently. Continuous

integration aims to improve the quality of software, and to reduce the time taken to deliver it, by replacing the traditional practice of applying quality control after

completing all development. (source: Wikipedia)

In practiceRun all tests and create some reports after every

commit.

Why is it useful? 1/2

• All tests are run after every commit.

• You always know if you can deploy after a commit.

• You know who broke a test.

Why is it useful? 2/2

• You can get pretty graphs

• Provides trends

• Motivational for developers

• First step to deploying from SCM

• No more “works for me”.

Meet Jenkins

What’s in it for you?

PHPUnit

Code coverage 1/4

Code Coverage 2/4

Code Coverage 3/4Requires xdebug, but it’s pretty cool.

Code coverage 4/4

• Takes some time to generate

• By default: only files included in test are part of the coverage.

• Coverage < Assertions

phploc

Plots

Checkstyle

Copy paste detector

PHP Depend

PHP depend, php mess detector etc

• Do fancy analysis on your code

• Create pretty diagrams

• Take a lot of time

• Little value (YMMV)

How to set it up

Vagrant

• Create and configure lightweight, reproducible, and portable development environments.

• Works with VirtualBox and Chef

Vagrant

• Allows you create VMs and deploy them with software from a Chef recipe.

• Many open source Chef recipes available.

• https://github.com/fnichol/chef-jenkins

Vagrantfile config.vm.customize do |vm| vm.memory_size = 1536 end config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "cookbooks" chef.json = { :jenkins => { :server => { :plugins => %w(checkstyle clover dry htmlpublisher jdepend plot pmd violations xunit git github) } } } chef.add_recipe("vagrant_main") end

Chef recipe%w{pdepend/PHP_Depend-beta phpmd/PHP_PMD-alpha phpunit/phpcpd phpunit/phploc phpunit/test_helpers PHPDocumentor PHP_CodeSniffer digitalsandwich/Phake phpunit/PHP_CodeBrowser phpunit/PHPUnit}.each do |pear_package| php_pear pear_package do options "--alldeps" action :install endend

Install PHP specific stuff

• Jenkins PHP manual and templates provided by Sebastian Bergmann.

• http://jenkins-php.org/

Tell Jenkins what to do

• Create build.xml

• Lives in your code

• Create a Job in Jenkins

• Point to your SCM

Configure Jenkins

• After running build.xml, lots of XML files are generated.

• You can install plugins in Jenkins which understand these XML files

• Configure Jenkins plugins to read these files and “publish” them.

• Optionally: do some stuff after build succeeds.

Some CI tips

Get fast hardware

Don’t run more than you need

• Consider if you want to wait every build on phpmd, pdepend etc.

• Alternatively: clone your job and run tests only in one job and analysis in other job.

Use SCM tags

• Jenkins can push tags to your SCM if a build succeeds

• Combined with tags on deploy very convenient

Make sure production & Jenkins are identical

• Different platforms? --> Bugs.

• Different PHP versions? --> Bugs.

• Different MySQL versions? --> Bugs.

Integrate with your dashboards

Integrate with chat

Q & Awillem@mollie.nl

We’re hiring