One Click Deployment with Jenkins - PHP Unconference 2011

96
© 2011 Mayflower GmbH Florian Anderiasch / Thorsten Rinne PHP Unconference 2011, Hamburg One Click Deployment with Jenkins

description

 

Transcript of One Click Deployment with Jenkins - PHP Unconference 2011

Page 1: One Click Deployment with Jenkins - PHP Unconference 2011

© 2011 Mayflower GmbH

Florian Anderiasch / Thorsten Rinne PHP Unconference 2011, Hamburg

One Click Deployment with Jenkins

Page 2: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 2

DevOp„I rant a lot“

@anderiasch

Page 3: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Team Lead / Scrum MasterHead of Open Source Labs

@ThorstenRinne3

Page 4: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Who are you?

4

Page 5: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Developers?

5

Page 6: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Administrators?

6

Page 7: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

DevOps?

7

Page 8: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continuous Integration?

8

Page 9: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

How much time do you need for a release?

9

Page 10: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

More than a year?

10

Page 11: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

6 - 12 months?

11

Page 12: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

1 - 6 months?

12

Page 13: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

2 - 4 weeks?

13

Page 14: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

1 - 14 days?

14

Page 15: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

1 - 24 hours?

15

Page 16: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Less than 15 minutes?

16

Page 17: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

15 Minutes!

17

Page 18: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Why One Click Deployment?

18

Page 19: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Everything is getting faster.

19

Page 20: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Faster feedback from your customer / user

20

Page 21: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Faster ROI (return on invest)

21

Page 22: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Faster responseif the market changes

22

Page 23: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 23Developers are lazy.

Page 24: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Basic requirements

24

Page 25: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Agile software development

25

Page 26: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Scrum or Kanban

26

Page 27: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Test Driven Development

27

Page 28: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 28

Page 29: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continuous Integration

29

Page 30: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continuous Inspection

30

Page 31: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Refactoring

31

Page 32: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 32

Page 33: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 32

ScrumKanban

Page 34: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 32

ScrumKanban

ContinuousIntegration

Page 35: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 32

ScrumKanban

ContinuousIntegration

ContinuousInspection

Page 36: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continuous Deployment

32

ScrumKanban

ContinuousIntegration

ContinuousInspection

Page 37: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Things you don‘t want.

33

Page 38: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Having your SVN repo in your webserver‘s docroot.

34

Page 39: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Using SSH and vi and your root account on the live

server. Never.

35

Page 40: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Who‘s still doing this? :-)

36

Page 41: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 37

Page 42: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

What do we need?

38

Page 43: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

First: a central build server

39

Page 44: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 40

Page 45: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continous Testing with PHPUnit

41

Page 46: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Advantages

42

Page 47: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Test results at one central page

43

Page 48: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Software metrics at one central page

44

Page 49: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Errors can be identified fast and then fixed

45

Page 50: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Awareness

46

Page 51: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 47

Awareness!

Page 52: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continuous Integration in PHP projects

48

Page 53: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

PHPUnitDocBlox

49

Page 54: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Continuous Inspection in PHP projects

50

Page 55: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

PHPCSPHP Depend

PHPMDphpcpd

jslint

51

Page 56: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

jslint?yes!

52

Page 57: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Infrastructure

53

Page 58: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 54

Page 59: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Developer VMUbuntu 11.04

55

Page 60: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Testing VM + Jenkins VM:Ubuntu 11.04

56

Page 61: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Staging VMs:Frontend: Ubuntu 11.04

Backend: Ubuntu 10.04 LTS

57

Page 62: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

amazon AWS live:Frontend: Ubuntu 11.04

Backend: Ubuntu 10.04 LTS

58

Page 63: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Front NodesVarnishnginx

PHP 5.3 with APCZend Framework 1.11

dojo toolkit 1.6Doctrine 2.1

59

Page 64: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 60

Backend NodesMySQL Master/Slave

Apache SolrPHP 5.3 with APC

RabbitMQejabberd

Page 65: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Development workflow

61

Page 66: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

1. git workflow

62

$ git add Foo.php$ git commit -m ″Bar″$ ant jslint$ ant phpunit ...$ git push

Page 67: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

2. Post commit hook

63

Build triggered on Jenkins

Page 68: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Jenkins build checks

64

Page 69: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

1. PHPUnit Build:Unittests

Controller Tests (Zend_Test)PHP Code Coverage

65

Page 70: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

2. Debian Package Build

66

Page 71: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

3. Deploy to staging4. Deploy staging to live

67

Page 72: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

What is a build process?

68

Page 73: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

ant syncant clean

ant db-updateparallelTasks:

ant phpunitant phpcbant deb

69

Page 74: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<target name="phpunit" depends="db-test" description="Run all tests"> <exec executable="phpunit" failonerror="true"> <arg line="--configuration ${basedir}/tests/phpunit-verbose.xml ${basedir}/tests/AllTests.php" /> </exec></target>

70

ant phpunit

Page 75: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

parallelTasks:php_depend

phpmdphpunitphpcpdphpcsjslint

71

Page 76: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 72

Build Debian Packageant autoloaderant phpunitant clean

ant compilejsant compilecss

Page 77: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<target name="deb" depends="autoloader,phpunit-coverage,clean,autoloader,compilejs,compilecss" description="Generate Debian package"> <exec executable="gpg"> <arg value="--armor" /> <arg value="--import" /> <arg value="scripts/build/deb/mapolis.mayflower.de.pgp" /> </exec> <buildnumber />

73

ant deb (I)

Page 78: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<exec executable="git" outputproperty="githash"> <arg value="describe" /> <arg value="--always" /> <arg value="--match" /> <arg value="" /> </exec> <touch file="debian/changelog" /> <move file="debian/changelog" tofile="debian/changelog.old" />

74

ant deb (II)

Page 79: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<exec executable="git" output="debian/changelog.new"> <arg value="log" /> <arg value="-n" /> <arg value="1" /> <arg value='--format=format:mapolis-web (${build.number}-${githash}) unstable; urgency=low%n%n * %s%n%n -- %an &lt;%ae&gt; %aD%n%n' /> </exec>

75

ant deb (III)

Page 80: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<concat destfile="debian/changelog"> <fileset file="debian/changelog.new" /> <fileset file="debian/changelog.old" /> </concat> <delete file="debian/changelog.new" /> <delete file="debian/changelog.old" />

76

ant deb (IV)

Page 81: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<exec executable="dpkg-buildpackage"> <arg value="-b" /> <arg value="-v${build.number}-${githash}" /> <arg value="-Zlzma" /> <arg value="-z9" /> <arg value="-k78532445" /> <arg value="-pgpg" /> <arg value="-sgpg" /> <arg value="-mMayflower Mapolis Team &lt;[email protected]&gt;" /> </exec>

77

ant deb (V)

Page 82: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

<move todir="build/deb/"> <fileset dir="${basedir}/../"> <include name="mapolis*.deb" /> <include name="mapolis*.changes" /> </fileset> </move> <exec executable="dpkg-buildpackage"> <arg value="-Tclean" /> </exec> </target>

78

ant deb (VI)

Page 83: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Deploy Stagingant clean

ant deb-signant db-staging-upscp to all hosts

79

Page 84: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 80

Deploy Staging to livescp to all hosts

Page 85: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Disadvantages and problems

81

Page 86: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Build time15 min on harddisk

massive disk i/o4 min on ramdisk :-)

82

Page 87: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Complexity beginning such a infrastructure

83

Page 88: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Jenkins:Single point of failure!

84

Page 89: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Cool stuff which is now possible

85

Page 90: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 86

Deploy by customer. :-)

Page 91: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I 87

Jenkins Chuck Norris Plugin

Page 92: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

git bisect start $BAD $GOOD

88

Page 93: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Minimum time from bugreport to deploy:

30 minutes

89

Page 94: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

$ git branch hotfix-2011-08-22$ git checkout hotfix-2011-08-22$ git reset --hard "last stable sha-1"$ git cherry-pick "hotfix sha-1"$ echo build.number=23 > build.number$ ant deb$ scp build/deb/*.deb xyz.amazonaws.com:/opt/repository/$ git checkout master$ git push origin hotfix-2011-08-10

90

Page 95: One Click Deployment with Jenkins - PHP Unconference 2011

Continuous Improvement in PHP Projects I Mayflower GmbH I 25th February I

Questions?

91

Page 96: One Click Deployment with Jenkins - PHP Unconference 2011

Thank you very much for your attention!

© 2011 Mayflower GmbH

Contact Florian [email protected]+49 89 242054-1134

Mayflower GmbHMannhardtstr. 680538 MünchenGermany

Thorsten [email protected]+49 89 242054-31

Mayflower GmbHMannhardtstr. 680538 MünchenGermany