$30 off During Our Annual Pro Sale. View Details »

Setting up a Continuous Delivery environment in 3 hours #zceu

Mike van Riel
November 18, 2013

Setting up a Continuous Delivery environment in 3 hours #zceu

The workshop slides for the talk 'Setting up a Continuous Delivery environment in 3 hours' at ZendCon Europe 2013

Mike van Riel

November 18, 2013
Tweet

More Decks by Mike van Riel

Other Decks in Technology

Transcript

  1. Continuous Deployment
    in 3 hours
    Mike van Riel
    Mike van Riel · @mvriel

    View Slide

  2. https://joind.in/9283
    About me

    I am Mike van Riel
     @mvriel

    View Slide

  3. https://joind.in/9283
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    View Slide

  4. https://joind.in/9283
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    Software Composer
    at Ingewikkeld

    View Slide

  5. https://joind.in/9283
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    Software Composer
    at Ingewikkeld

    Foster father of two
    cute dogs

    View Slide

  6. https://joind.in/9283
    What is Continuous Deployment,
    and what is Continuous Delivery?

    View Slide

  7. https://joind.in/9283

    View Slide

  8. https://joind.in/9283
    The rules
    Mike van Riel

    View Slide

  9. https://joind.in/9283
    Feedback
    Feedback
    Feedback

    View Slide

  10. https://joind.in/9283
    Versioning is
    key

    View Slide

  11. https://joind.in/9283
    Build your artifacts
    once

    View Slide

  12. https://joind.in/9283

    View Slide

  13. https://joind.in/9283
    one
    deployment process
    to rule them all
    Environments

    View Slide

  14. https://joind.in/9283
    Feedback
    Mike van Riel

    View Slide

  15. https://joind.in/9283

    View Slide

  16. https://joind.in/9283
    Versioning
    Mike van Riel

    View Slide

  17. https://joind.in/9283
    Your Code, Configuration
    and Environment must be
    in Version Control

    View Slide

  18. https://joind.in/9283
    “To branch, or not to branch.
    That is the question.”
    - Bill Shakespeare*

    View Slide

  19. https://joind.in/9283
    Concepts
    Mike van Riel

    View Slide

  20. https://joind.in/9283
    Environments

    View Slide

  21. https://joind.in/9283
    Deployment Pipeline

    View Slide

  22. https://joind.in/9283
    Deployment Pipeline - optimized

    View Slide

  23. https://joind.in/9283
    Config flags

    Toggles features on and off

    Allows a team to continuously integrate

    Can be used for Canary testing

    Provides a rollback in case of flawed
    functionality

    View Slide

  24. https://joind.in/9283
    Aids
    Mike van Riel

    View Slide

  25. https://joind.in/9283
    Continuous Integration Servers
    Jenkins TeamCity Thoughtworks
    Go

    View Slide

  26. https://joind.in/9283
    Analysis tools

    PHPUnit

    Behat

    phpDocumentor

    PHP_CodeSniffer

    PHP_Depend

    PHP_PMD

    phploc

    phpcpd

    View Slide

  27. https://joind.in/9283
    Build and deployment tools

    Phing

    Ant

    Make

    Capistrano

    Webistrano

    Deployinator

    Maven

    View Slide

  28. https://joind.in/9283
    More feedback

    Logstash

    Graphite

    Nagios

    View Slide

  29. https://joind.in/9283
    Exercises
    Mike van Riel

    View Slide

  30. https://joind.in/9283
    Environment

    Ubuntu 12.04

    Apache

    MySQL

    PHP 5.3

    XDebug

    One vhost
    – dev.www.blog.com

    Packages
    – Git
    – Augeas-tools
    – Libaugeas-dev
    – Libaugeas-ruby
    – Jenkins

    View Slide

  31. https://joind.in/9283
    Exercise 1
    Determine your workflow

    View Slide

  32. https://joind.in/9283
    Goal

    Think before you start

    Determine your process and workflow

    Does your current flow match with
    Continuous Deployment

    View Slide

  33. https://joind.in/9283
    Think about the following

    Versioning your application

    Versioning your environment

    Version numbering

    Which tools to use

    How to react on a build failure

    View Slide

  34. https://joind.in/9283
    Versioning

    Master / trunk should always be deployable

    Any change in master / trunk should result in
    a release candidate

    Release branches, develop mainlines and
    other constructs do not play a role with
    Continuous Deployment
    – There are exceptions

    View Slide

  35. https://joind.in/9283
    Exercise 2
    Planning your deployment pipeline

    View Slide

  36. https://joind.in/9283
    Goal

    Determine how to start automating your build
    and deployment process

    Review your deployment strategy

    Automate your deployment process using
    phing

    View Slide

  37. https://joind.in/9283
    Stages

    Commit stage
    – Pull changes
    – Clean workspace
    – Initialize workspace
    – Run unit tests

    Deploy stage
    – Upload your
    application
    – Switch symlink

    View Slide

  38. https://joind.in/9283
    Deployment strategy

    Have a symlink representing your current
    release

    Upload your new release to a separate folder

    Integrate configuration in the new folder

    Create symlink of the new release

    Move the symlink of the new release over the
    current using `mv -Tf`

    View Slide

  39. https://joind.in/9283
    Exercise 3
    Apply Continuous Integration

    View Slide

  40. https://joind.in/9283
    Goal

    Setup a job in Jenkins

    Add deployment as a post-build action

    Execute our first automated build and
    deployment

    View Slide

  41. https://joind.in/9283
    Exercise 4
    Adding support for environments
    using parameters

    View Slide

  42. https://joind.in/9283
    Goal

    Extract all variable deployment options into
    parameters

    Learn how to switch between environments

    View Slide

  43. https://joind.in/9283
    Exercise 5
    Adding a staging environment

    View Slide

  44. https://joind.in/9283
    Goal

    Add a new staging environment to puppet

    Change our deployment action to deploy to
    staging instead of production
    – using the changes of last exercise

    View Slide

  45. https://joind.in/9283
    Exercise 6
    Switching to Continuous Delivery

    View Slide

  46. https://joind.in/9283
    Goal

    Add a new view for our project

    Add a new deploy job

    Persist workspace between jobs

    Try out our new process

    View Slide

  47. https://joind.in/9283
    Adding a new Deploy job

    Add a new job `blog-deploy`

    Configure `blog` job to archive the build

    Configure `blog-deploy` job to use the
    archived build

    View Slide

  48. https://joind.in/9283
    Exercise 7
    Adding a UAT stage

    View Slide

  49. https://joind.in/9283
    Goal

    Create a Behat test

    Alter our build file and add a UAT stage

    Add a new UAT job

    Persist workspace between jobs

    Automatically trigger UAT job after `blog` job

    Move deployment to staging from `blog` to UAT job

    Test our new process

    View Slide

  50. https://joind.in/9283
    UAT Stage

    May run longer than 5 minutes

    Can trigger a deployment to staging for
    exploratory testing

    Automate!

    View Slide

  51. https://joind.in/9283
    Bonus exercise 1
    Using the pipeline plugin

    View Slide

  52. https://joind.in/9283
    Goal

    Use the pipeline plugin to create a new view
    with your process

    Walk through your process

    View Slide

  53. https://joind.in/9283
    Questions?
    Please leave feedback on Joind.in, I'd appreciate it.

    View Slide

  54. https://joind.in/9283
    Credits

    http://www.flickr.com/photos/joebenjamin/5009411920/

    http://en.wikipedia.org/wiki/Continuous_delivery

    http://www.flickr.com/photos/robertlemke/4383863479

    http://continuousdelivery.com/2010/09/deployment-pipeline-
    anti-patterns/

    View Slide

  55. https://joind.in/9283
    Continuous Deployment
    in 3 hours
    Mike van Riel
    Mike van Riel · @mvriel

    View Slide

  56. https://joind.in/9283
    About me

    I am Mike van Riel
     @mvriel

    View Slide

  57. https://joind.in/9283
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    View Slide

  58. https://joind.in/9283
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    Software Composer
    at Ingewikkeld

    View Slide

  59. https://joind.in/9283
    About me

    I am Mike van Riel

    Lead Developer for
    phpDocumentor

    Software Composer
    at Ingewikkeld

    Foster father of two
    cute dogs

    View Slide

  60. https://joind.in/9283
    What is Continuous Deployment,
    and what is Continuous Delivery?

    View Slide

  61. https://joind.in/9283

    View Slide

  62. https://joind.in/9283
    The rules
    Mike van Riel

    View Slide

  63. https://joind.in/9283
    Feedback
    Feedback
    Feedback

    View Slide

  64. https://joind.in/9283
    Versioning is
    key

    View Slide

  65. https://joind.in/9283
    Build your artifacts
    once

    View Slide

  66. https://joind.in/9283

    View Slide

  67. https://joind.in/9283
    one
    deployment process for all
    environments

    View Slide

  68. https://joind.in/9283
    Versioning
    Mike van Riel

    View Slide

  69. https://joind.in/9283
    Your Code, Configuration
    and Environment must be
    in Version Control

    View Slide

  70. https://joind.in/9283
    “To branch, or not to branch.
    That is the question.”
    - Bill Shakespeare*

    View Slide

  71. https://joind.in/9283
    Concepts
    Mike van Riel

    View Slide

  72. https://joind.in/9283
    Environments

    View Slide

  73. https://joind.in/9283
    Deployment Pipeline

    View Slide

  74. https://joind.in/9283
    Deployment Pipeline - optimized

    View Slide

  75. https://joind.in/9283
    Config flags

    Toggles features on and off

    Allows a team to continuously integrate

    Can be used for Canary testing

    Provides a rollback in case of flawed
    functionality

    View Slide

  76. https://joind.in/9283
    Aids
    Mike van Riel

    View Slide

  77. https://joind.in/9283
    Continuous Integration Servers
    Jenkins TeamCity Thoughtworks
    Go

    View Slide

  78. https://joind.in/9283
    Analysis tools

    PHPUnit

    Behat

    phpDocumentor

    PHP_CodeSniffer

    PHP_Depend

    PHP_PMD

    phploc

    phpcpd

    View Slide

  79. https://joind.in/9283
    Build and deployment tools

    Phing

    Ant

    Make

    Capistrano

    Webistrano

    Deployinator

    Maven

    View Slide

  80. https://joind.in/9283
    More feedback

    Logstash

    Graphite

    Nagios

    View Slide

  81. https://joind.in/9283
    Exercises
    Mike van Riel

    View Slide

  82. https://joind.in/9283
    Environment

    Ubuntu 12.04

    Apache

    MySQL

    PHP 5.3

    XDebug

    One vhost
    – dev.www.blog.com

    Packages
    – Git
    – Augeas-tools
    – Libaugeas-dev
    – Libaugeas-ruby
    – Jenkins

    View Slide

  83. https://joind.in/9283
    The Project - Blog

    URL:
    http://dev.www.blog.com/index.php/blog/

    Jenkins: http://dev.www.blog.com:8080

    Path: /vagrant/app

    Git: file:///vagrant/app

    View Slide

  84. https://joind.in/9283
    Exercise 1
    Determine your workflow

    View Slide

  85. https://joind.in/9283
    Goal

    Think before you start

    Determine your process and workflow

    Does your current flow match with
    Continuous Deployment

    View Slide

  86. https://joind.in/9283
    Think about the following

    Versioning your application

    Versioning your environment

    Version numbering

    Which tools to use

    How to react on a build failure

    View Slide

  87. https://joind.in/9283
    Versioning

    Master/trunk should always be deployable

    Any change in master / trunk should result in
    a release candidate

    Release branches, develop mainlines and
    other constructs do not play a role with
    Continuous Deployment
    – There are exceptions

    View Slide

  88. https://joind.in/9283
    Exercise 2
    Planning your deployment pipeline

    View Slide

  89. https://joind.in/9283
    Goal

    Determine how to start automating your build
    and deployment process

    Review your deployment strategy

    Automate your deployment process using
    phing

    View Slide

  90. https://joind.in/9283
    Stages

    Commit stage
    – Pull changes
    – Clean workspace
    – Initialize workspace
    – Run unit tests

    Deploy stage
    – Upload your
    application
    – Switch symlink

    View Slide

  91. https://joind.in/9283
    Deployment strategy

    Have a symlink representing your current
    release

    Upload your new release to a separate folder

    Integrate configuration in the new folder

    Create symlink of the new release

    Move the symlink of the new release over the
    current using `mv -Tf`

    View Slide

  92. https://joind.in/9283
    Exercise 3
    Apply Continuous Integration

    View Slide

  93. https://joind.in/9283
    Goal

    Setup a job in Jenkins

    Add deployment as a post-build action

    Execute our first automated build and
    deployment

    View Slide

  94. https://joind.in/9283
    Exercise 4
    Adding support for environments
    using parameters

    View Slide

  95. https://joind.in/9283
    Goal

    Extract all variable deployment options into
    parameters

    Learn how to switch between environments

    View Slide

  96. https://joind.in/9283
    Exercise 5
    Adding a staging environment

    View Slide

  97. https://joind.in/9283
    Goal

    Add a new staging environment to puppet

    Change our deployment action to deploy to
    staging instead of production
    – using the changes of last exercise

    View Slide

  98. https://joind.in/9283
    Exercise 6
    Switching to Continuous Delivery

    View Slide

  99. https://joind.in/9283
    Goal

    Add a new view for our project

    Add a new deploy job

    Persist workspace between jobs

    Try out our new process

    View Slide

  100. https://joind.in/9283
    Adding a new Deploy job

    Add a new job `blog-deploy`

    Configure `blog` job to archive the build

    Configure `blog-deploy` job to use the
    archived build

    View Slide

  101. https://joind.in/9283
    Exercise 7
    Adding a UAT stage

    View Slide

  102. https://joind.in/9283
    Goal

    Create a Behat test

    Alter our build file and add a UAT stage

    Add a new UAT job

    Persist workspace between jobs

    Automatically trigger UAT job after `blog` job

    Move deployment to staging from `blog` to UAT job

    Test our new process

    View Slide

  103. https://joind.in/9283
    UAT Stage

    May run longer than 5 minutes

    Can trigger a deployment to staging for
    exploratory testing

    Automate!

    View Slide

  104. https://joind.in/9283
    Bonus exercise 1
    Using the pipeline plugin

    View Slide

  105. https://joind.in/9283
    Goal

    Use the pipeline plugin to create a new view
    with your process

    Walk through your process

    View Slide

  106. https://joind.in/9283
    Questions?
    Please leave feedback on Joind.in, I'd appreciate it.

    View Slide

  107. https://joind.in/9283
    Credits

    http://www.flickr.com/photos/joebenjamin/5009411920/

    http://en.wikipedia.org/wiki/Continuous_delivery

    http://www.flickr.com/photos/robertlemke/4383863479

    http://continuousdelivery.com/2010/09/deployment-pipeline-
    anti-patterns/

    View Slide