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
Theory
     In 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 practice
Run 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/4
Requires 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
Plots
 phploc
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
  end
end
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 &A
willem@mollie.nl
We’re hiring

Continuous Integration at Mollie

  • 1.
    Continuous Integration for PHP www.mollie.nl
  • 2.
    Contents • About Mollie •What is CI • What’s in it for you? • How to set it up • Tips • Q&A
  • 3.
    • Payment ServiceProvider • iDEAL, Pay-per-call, Premium SMS, etc. • SMS gateway • HTTP API, SMPP, Email to SMS, etc. • Located in Amsterdam, near Vondelpark • Four developers
  • 4.
    Codebase 1/2 • Mainproject: 250K LOC • New code is pretty good, but... • lots of code created around 2004 (when magic_quotes was cool)
  • 5.
    Codebase 2/2 • Gitas SCM • Also: • Plugins for OpenCart, Magento, WHCMS • Example API classes • Internal projects
  • 6.
    Technology • Nothing toocomplicated: • Nginx • PHP • MySQL • Redis
  • 7.
  • 8.
    Theory In 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)
  • 9.
    In practice Run alltests and create some reports after every commit.
  • 10.
    Why is ituseful? 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.
  • 11.
    Why is ituseful? 2/2 • You can get pretty graphs • Provides trends • Motivational for developers • First step to deploying from SCM • No more “works for me”.
  • 12.
  • 15.
  • 19.
  • 23.
  • 24.
  • 25.
    Code Coverage 3/4 Requiresxdebug, but it’s pretty cool.
  • 26.
    Code coverage 4/4 •Takes some time to generate • By default: only files included in test are part of the coverage. • Coverage < Assertions
  • 27.
  • 30.
  • 31.
  • 32.
  • 33.
    PHP depend, phpmess detector etc • Do fancy analysis on your code • Create pretty diagrams • Take a lot of time • Little value (YMMV)
  • 34.
  • 35.
    Vagrant • Create andconfigure lightweight, reproducible, and portable development environments. • Works with VirtualBox and Chef
  • 36.
    Vagrant • Allows youcreate VMs and deploy them with software from a Chef recipe. • Many open source Chef recipes available. • https://github.com/fnichol/chef-jenkins
  • 37.
    Vagrantfile config.vm.customizedo |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
  • 38.
    Chef recipe %w{pdepend/PHP_Depend-beta phpmd/ PHP_PMD-alphaphpunit/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 end end
  • 39.
    Install PHP specificstuff • Jenkins PHP manual and templates provided by Sebastian Bergmann. • http://jenkins-php.org/
  • 40.
    Tell Jenkins whatto do • Create build.xml • Lives in your code • Create a Job in Jenkins • Point to your SCM
  • 42.
    Configure Jenkins • Afterrunning 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.
  • 44.
  • 45.
  • 47.
    Don’t run morethan 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.
  • 48.
    Use SCM tags •Jenkins can push tags to your SCM if a build succeeds • Combined with tags on deploy very convenient
  • 49.
    Make sure production &Jenkins are identical • Different platforms? --> Bugs. • Different PHP versions? --> Bugs. • Different MySQL versions? --> Bugs.
  • 50.
  • 54.
  • 55.
  • 56.