際際滷

際際滷Share a Scribd company logo
Continuous Integration
Stop procrastinating and build often!
Who am I?
Patrick Mizer
Chief Architect at SpareFoot
ZCE: PHP4, PHP5, and ZF
patrick@sparefoot.com
github.com/maximizer
We help consumers search,
compare, and book self
storage online.
Im not supposed to say this but
Think Hotels.com, but for self storage.
We have been using a
Continuous Integration
workflow since 2009
SpareFoot in 2009
 20 Visits per day
 1 RackSpace cloud instance
 2 Developers
 1 Application
 5-10 builds per day
 Deployed whenever -> % svn up
SpareFoot Today
 2 million visitors per month
 > 50 AWS EC2 instances
 35 developers
 7 product teams.
 100-200 builds per day
 Continuous Delivery
What I will cover...
 What is CI?
 Why do it?
 The Jenkins CI Server
 What does a CI workflow look like?
 Build Tools
 Testing and Analysis
 Notification
 Lessons Learned
I want to clarify something..
Continuous something...
Continuous Integration
Continuous Delivery
Continuous Deployment
Continuous something...
Continuous
Integration
Continuous
Delivery
Continuous
Deployment
Continuous something...
Version
Control
Deploy to
Staging
Automated
Tests
AUTO AUTO
Continuous
Integration
Continuous
Delivery
Continuous
Deployment
Continuous something...
Version
Control
Deploy to
Staging
Automated
Tests
Acceptance
Tests
Deploy to
Production
AUTO AUTO AUTO MANUAL
Version
Control
Deploy to
Staging
Automated
Tests
AUTO AUTO
Continuous
Integration
Continuous
Delivery
Continuous
Deployment
Continuous something...
Version
Control
Deploy to
Staging
Automated
Tests
Acceptance
Tests
Deploy to
Production
AUTO AUTO AUTO AUTO
Version
Control
Deploy to
Staging
Automated
Tests
Acceptance
Tests
Deploy to
Production
AUTO AUTO AUTO MANUAL
Version
Control
Deploy to
Staging
Automated
Tests
AUTO AUTO
Continuous
Integration
Continuous
Delivery
Continuous
Deployment
Continuous something...
Version
Control
Deploy to
Staging
Automated
Tests
Acceptance
Tests
Deploy to
Production
AUTO AUTO AUTO AUTO
Version
Control
Deploy to
Staging
Automated
Tests
Acceptance
Tests
Deploy to
Production
AUTO AUTO AUTO MANUAL
Version
Control
Deploy to
Staging
Automated
Tests
AUTO AUTO
Continuous
Integration
Continuous
Delivery
Continuous
Deployment
What is Continuous Integration?
CI is a software development process in which
developers integrate their work frequently.
Each integration is built and verified by
automated tests so that errors and
inconsistencies are detected and fixed as
quickly as possible.
What is Continuous Integration?
CI originated with Extreme Programming
CI is a process. It dictates no specific tooling.
So, why do it?
So, why do it?
Finding bugs late is costly
Local
Development
Staging
Production
Developers
QA &
Stakeholders
Your
Customers
Finding bugs late is costly
Integration Hell
Your changes to the booking service are
incompatible with mine. How do we merge
now?
When did we start using Guzzle 2.0? The
SDK requires 3.0 and composer wont let us
use both!
Integration Hell
Mainline
Developer C
Developer A
Developer B
Integration Hell
Mainline
Developer C
Developer A
Developer B
Integration Hell
Mainline
Developer C
Developer A
Developer B
Integration Hell
Mainline
Developer C
Developer A
Developer B
Integration Hell
Mainline
Developer C
Developer A
Developer B
Integration Hell
Mainline
Developer C
Developer A
Developer B
Poor Quality Codebase
Who the #$@# is using tabs instead of
spaces!?
We have 2 classes doing the exact same
thing
Poor Project Visibility
What is our test coverage?
How is our app performing?
No Deployable Code
It works on my machine!
I dont know why its not working on staging,
sounds like an ops problem.
We need to push a fix for this immediately.
CI attempts to mitigate these
 Finding bugs late is costly
 Integration hell
 Poor quality code base
 Poor project visibility
 No deployable code
Better code, faster development
Better code
 Code is tested early and often
 Standards enforced on every commit
Better code, faster development
Better code
 Code is tested early and often
 Standards enforced on every commit
Faster development
 Integration issues are found earlier
 Testing becomes part of everyones process
 Building is a non-event
Continuous Integration
Implementing a CI solution is pretty
straightforward.
Continuous Integration
 Maintain an SCM code repository
Continuous Integration
 Maintain an SCM code repository
 Create and automate the build
Continuous Integration
 Maintain an SCM code repository
 Create and automate the build
 Everyone commits to mainline (at least daily)
Continuous Integration
 Maintain an SCM code repository
 Create and automate the build
 Everyone commits to mainline (at least daily)
 Every commit to mainline is built
Continuous Integration
 Maintain an SCM code repository
 Create and automate the build
 Everyone commits to mainline (at least daily)
 Every commit to mainline is built
 Tests verified on a prod-like environment
Continuous Integration
 Maintain an SCM code repository
 Create and automate the build
 Everyone commits to mainline (at least daily)
 Every commit to mainline is built
 Tests verified on a prod-like environment
 Notify everyone of the results
Excuses
We're not big enough
Too much work
We don't have devops
We don't have tests
The CI Server
 Polls for changes
 Manages and monitors builds
 Notifies team of results
Jenkins
 Free Open Source (MIT License)
 Built on Java
 Fork of Hudson
 Plugins for everything
 Lots of resources
Easy to get going:
% sudo apt-get install jenkins
% sudo apt-get install jenkins-cli
Jenkins-php.org
Jenkins template for PHP projects put together
by Sebastian (yes, that Sebastian) Bergmann
Step-by-step Instructions:
 Template w/ plugins
 Build file
 Log formats
 Jenkins config
The CI workflow
 Developer commits code
 CI Server polls SCM for changes
 CI Server integrates and builds code
to the Integration Environment
 CI notifies team of result
The CI workflow
Push
The CI workflow
Poll
Push
The CI workflow
Poll
Build
Push
The CI workflow
Poll
Build
Test/Analyze
Push
The CI workflow
Poll
Build
Test/Analyze
Notify
Push
The Build
 Build dependencies
 Tests
 Static analysis
 Artifacts (docs, phar, etc)
 ...
Build tools...
Build tools...
But build files are only for
compiling.
Build tools...
Use a proper built tool
 Apache Ant (Java)
 Phing (PHP)
Apache Ant
 build.xml
 Targets and depends
 Java = threads ++
Anatomy of build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="some-php-project" default="build">
<target name="build" depends="phpunit"/>
<target name="phpunit" description="Run unit tests">
<exec executable="phpunit" failonerror="true"/>
</target>
</project>
SCM polling and build
The Integration Machine
 A reasonable facsimile of production
 Every commit is built here
 By yourself? Use Vagrant
Verifying the Build
Unit Tests Functional Tests
Selenium
But setting up selenium is
hard...
SauceLabs
SauceLabs
Testing is just the beginning
Static Analysis
Analysis of software without
actually executing the code.
Check your PHP syntax
PHP Lint
php -l foo.php
find . -name *.php -exec
php -l {};
PHP Lint
Coding Standards
PHP Code Sniffer
phpcs --standard=pear foo.php
PHP Code Sniffer
DRY
Copy page detector
phpcpd -min-lines=5 /src/service/*
Copy Paste Detector
Performance
Performance - Bonus
Phantomjs is a headless browser
based on Webkit with JS API
YSlow is a tool that analyzes web
pages and why theyre slow based on
Yahoos rules.
Phantomjs + YSlow = Awesomeness
Performance - Bonus
phantomjs yslow.js
-i grade -threshold "A"
-f junit
http://staging.sparefoot.com >
results.xml
Notification
Notification
Notification
Notification
Lessons Learned
Lessons Learned
Lessons Learned
Version all of you CI Config.
We didnt and now were
going back and rewriting it.
Lessons Learned
Building the DB
 Put your schema changes under version
control.
 Incorporate them into the build
 Fail when theres a problem. Make this the
only way to get schema changes to
production.
Git feature branching
Git feature branching solves
a separate problem.
Git feature branching
Master
Branch C
Branch A
Branch B
Our Git Workflow
commit commit PUSH
Branch
Merge
Pull
request
commit
PUSHcommit commit commit
Merge
Pull
request
MASTER
BRANCH B
BRANCH A
Branch + master
built to dev
environment and
tested.
Branch + master
built to dev
environment and
tested.
Master built to
staging
environment and
tested.
Play with Jenkins today!
github.com/
maximizer/vagrant-ci
% git clone github.com/maximizer/vagrant-ci.git
% vagrant up
http://localhost:8282
http://jenkins-php.org
Thank You!
Questions?
https://joind.in/13077
patrick@sparefoot.com
github.com/maximizer/vagrant-ci

More Related Content

CI