Continuous Integration
CODING & DEVELOPMENT | BORIS GORDON | FEBRUARY 7 2013
Introduction
About me
•
boztek on d.o. (http://drupal.org/user/134410)•
@boztek•
[email protected]2
Introduction
About you
3
Introduction
About you
3
•
Probably a developerIntroduction
About you
3
•
Probably a developer•
Maybe don’t know what CI is at allIntroduction
About you
3
•
Probably a developer•
Maybe don’t know what CI is at all•
Probably have some idea but don’t know where to startIntroduction
About you
3
•
Probably a developer•
Maybe don’t know what CI is at all•
Probably have some idea but don’t know where to start•
Wondering how/if it applies to Drupal projectsIntroduction
About you
3
•
Probably a developer•
Maybe don’t know what CI is at all•
Probably have some idea but don’t know where to start•
Wondering how/if it applies to Drupal projects•
Have some “scaling” concernsIntroduction
What we will cover
4
Introduction
What we will cover
4
•
MotivationIntroduction
What we will cover
4
•
Motivation•
Continuous integration basicsIntroduction
What we will cover
4
•
Motivation•
Continuous integration basics•
Getting startedIntroduction
What we will cover
4
•
Motivation•
Continuous integration basics•
Getting started•
Best practicesIntroduction
What we will cover
4
•
Motivation•
Continuous integration basics•
Getting started•
Best practices•
Building, testing and deployingIntroduction
What we will cover
4
•
Motivation•
Continuous integration basics•
Getting started•
Best practices•
Building, testing and deploying•
Continuous integration serversIntroduction
What we will
not
cover
5
Introduction
What we will
not
cover
5
•
Which software you need to install to integrate for youIntroduction
What we will
not
cover
5
•
Which software you need to install to integrate for you•
The perfect one size fits all project templateIntroduction
What we will
not
cover
5
•
Which software you need to install to integrate for you•
The perfect one size fits all project template•
How to install JenkinsIntroduction
What we will
not
cover
5
•
Which software you need to install to integrate for you•
The perfect one size fits all project template•
How to install Jenkins•
How to write Drupal testsIntroduction
What we will
not
cover
5
•
Which software you need to install to integrate for you•
The perfect one size fits all project template•
How to install Jenkins•
How to write Drupal tests•
I won’t really try to convince you that should be doing thisWhat’s the problem?
We are talking about construction
6
What’s the problem?
We are talking about construction
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
5. Fix bugs
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
5. Fix bugs
6. Testers review
6
What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
5. Fix bugs
6. Testers review
7. Fix bugs
6 Saturday, 9 February 13What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
5. Fix bugs
6. Testers review
7. Fix bugs
8. Deliver
6 Saturday, 9 February 13What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
5. Fix bugs
6. Testers review
7. Fix bugs
8. Deliver
6 Saturday, 9 February 13What’s the problem?
We are talking about construction
1. Pre-build (requirements, specs, etc.)
2. Design and develop and test locally
3. Deploy release to test server
4. Testers review
5. Fix bugs
6. Testers review
7. Fix bugs
8. Deliver
7 Saturday, 9 February 13Software Engineering 101
Not releasing defects is much cheaper than
fixing them later.
8
How can we fix?
Turns out it’s cheaper to fail faster and more
often.
9
How can we fix?
Problems with divide and conquer
10
How can we fix?
Integration is waste right?
11
How can we fix?
Integration is waste right?
11
“If it feels good, do it”?
12
“If it feels good, do it”?
Maybe if it’s painful, you aren’t doing it
enough
13
“If it feels good, do it”?
Maybe if it’s painful, you aren’t doing it
enough
13
“If it feels good, do it”?
Maybe if it’s painful, you aren’t doing it
enough
•
Integrating small changes reveals problems earlier13
“If it feels good, do it”?
Maybe if it’s painful, you aren’t doing it
enough
•
Integrating small changes reveals problems earlier•
Integrating regularly produces feedback quicker than integrating sporadically13
“If it feels good, do it”?
Maybe if it’s painful, you aren’t doing it
enough
•
Integrating small changes reveals problems earlier•
Integrating regularly produces feedback quicker than integrating sporadically13
“If it feels good, do it”?
Maybe if it’s painful, you aren’t doing it
enough
•
Integrating small changes reveals problems earlier•
Integrating regularly produces feedback quicker than integrating sporadically•
Maybe we should just integrate all the time?13
Continuous integration
Is that even possible?
14
Continuous integration
Is that even possible?
14
Continuous integration
Is that even possible?
•
Yes14
Continuous integration
Is that even possible?
•
Yes•
... sort of14
Continuous integration
Is that even possible?
•
Yes•
... sort of•
... with discipline14
Continuous integration
Is that even possible?
•
Yes•
... sort of•
... with discipline•
... and sufficient tools14
Continuous integration
How continuous is continuously?
“Continuously is more often than
you think”
- Jez Humble
15
CI is a practice
It’s not really about tools
It is about getting past our
adolescent surety that “I know better
than everyone else and all I need is
to be left alone to be the greatest.”
- Kent Beck
16
The CI mindset
•
Without CI : consider your application’s default state broken (aka “under development”)•
With CI : the starting point for any development work is a stable, robust, tested application•
Mistakes are made early and quickly and addressedwhen it’s cheapest to fix
Goals and principles
17
CI is a practice
18
In other words
•
“apt-get install jenkins” !== CI•
Installing and maintaining a CI server may be an IT/Ops job•
Doing CI is something the developers practiceDefining some terms
Getting started
19
Defining some terms
•
build : some version-able, deployable, stand alone artefacts that can be tracked across differentenvironments
Getting started
19
Defining some terms
•
build : some version-able, deployable, stand alone artefacts that can be tracked across differentenvironments
•
test : examine build artefacts and has own artefactsGetting started
19
Defining some terms
•
build : some version-able, deployable, stand alone artefacts that can be tracked across differentenvironments
•
test : examine build artefacts and has own artefacts•
deploy : moving a build aroundGetting started
19
Start with the essentials
•
check into mainline regularly•
test everything (that can break)•
building and testing should be fastImplementing CI
20
Regular “mainline checkins”
Implementing CI
21
Comprehensive automated tests
Confidence in a build is dependent on the breadth and quality of tests.
•
Testing needs to be as frictionless as possible•
Tests need to run fast•
Drupal simpletest is pretty slow•
But there are other types of tests and you don’t have to run all of them all the timeImplementing CI
22
Comprehensive automated tests
Some types of tests and recommended tools. 1. Unit tests - PHPUnit - DrupalUnittestCase 2. Functional tests - Simpletest 3. Smoke tests
- Shell scripts, simpletest
4. Regression tests (use one of the above) 5. Automated acceptance tests
- Behat with mink or selenium
Implementing CI
23
Comprehensive automated tests
That’s a lot of tests!
Different types of tests can be run at different stages of a CI pipeline
Implementing CI
24
Productive development environments
Consistent development environments are important.
•
Writing tests needs to be as frictionless as possible too•
Tests need to run fast locally•
Ideally all tests need to be runnable locallyImplementing CI
25
Productive development environments
Configuration and data should be versioned
•
Build scripts•
Test data•
Deploy configurations•
Dependency managementImplementing CI
26 Saturday, 9 February 13Productive development environments
Building and testing should be
fast
Implementing CI
27
Productive development environments
Why bother?
Like TDD it can reveal bad smells you might otherwise ignore
Implementing CI
28
Some best practices
Doing Continuous Integration
29
Some best practices
•
Don’t check in on a broken buildDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main lineDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main line•
Keep the main line build stableDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main line•
Keep the main line build stable•
Know how to manage instabilityDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main line•
Keep the main line build stable•
Know how to manage instability•
Take responsibilityDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main line•
Keep the main line build stable•
Know how to manage instability•
Take responsibility•
Don’t forget about the architectureDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main line•
Keep the main line build stable•
Know how to manage instability•
Take responsibility•
Don’t forget about the architecture•
Beware slow testsDoing Continuous Integration
29
Some best practices
•
Don’t check in on a broken build•
Run tests (locally) before merging into the main line•
Keep the main line build stable•
Know how to manage instability•
Take responsibility•
Don’t forget about the architecture•
Beware slow tests•
Code style mattersDoing Continuous Integration
29
Build
An automated build.
This is the best place to start.
Managing a Drupal Pipeline
30
Build
Managing a Drupal Pipeline
31
Build
. !"" README.md !"" build !"" build.properties !"" build.properties.dist !"" build.xml !"" db !"" src !"" test #"" toolsManaging a Drupal Pipeline
32
Build - Demo
$> phing
Managing a Drupal Pipeline
33
Test
Unit tests and integration tests are really part of the build. Static analysis is part of the build.
Managing a Drupal Pipeline
34
Test
So we can run tests with Phing.
Managing a Drupal Pipeline
35
Deploy
•
Capistrano•
Phing•
Environment differencesManaging a Drupal Pipeline
36
Automate all the builds!
Once you have automated builds, automated tests and automated deployments it’s time to wire them up.
•
Jenkins•
Travis CI•
ThoughtWorks GoContinuous Integration Servers
37
Tie it all together with robots
A CI server is the robot that sits between your version control system and your build system.
Robots can do heavier lifting
Continuous Integration Servers
38
Jenkins
Jenkins is a popular CI server that provides the hub
between your version control and build / test / deploy tools.
•
VCS integrations•
Reporting•
Triggering•
Configurable UI / dashboardContinuous Integration Servers
39
Travis CI
Continuous Integration Servers
40
References and further reading
Continuous Delivery by Jez Humble
http://www.amazon.com/Continuous-Delivery-Deployment-Automation-Addison-Wesley/dp/0321601912
Continuous Integration by Duvall, Matyas and Glover
http://www.amazon.com/Continuous-Integration-Improving-Software-Reducing/dp/ 0321336380/ref=sr_1_1?
s=books&ie=UTF8&qid=1360206726&sr=1-1&keywords=continuous+integration
Drupal phing build.xml
http://reload.github.com/phing-drupal-template/
Continuous Integration Servers
41
References and further reading
http://github.com/boztek/drupal-project-template
Continuous Integration Servers
42
Integration complete
Questions
•
boztek on d.o. (http://drupal.org/user/134410)•
@boztek•
[email protected]43