Symfony 2 under control


Published on

Symfony Camp 2013 UA.
Continuous Integration and Automated Deployments for Symfony-based projects

P.S. Original PPTX presentation contains a lot of notes

Published in: Software, Technology
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Speech includes not only slides and copy-paste from manual, but also a real practice P.S. A lot of well-known demotivators and gags are included)
  • практика разработки программного обеспечения, которая заключается в выполнении частых автоматизированных сборок проекта для скорейшего выявления и решения интеграционных проблем
  • envs: dev/ci/qa/staging/uat/production
  • What to build?
    Install vendors
    Perform static analysis& validation
    Prepare assets
    Run tests
    Compress into archive
  • Ant: From Java world, XML declarative config, Can run tasks in parallel, No PHP-specific tasks, Could be extended (Java), IDE support
    Phing: Written in PHP, Ant config syntax, All tasks by default are running in the single PHP process, Could be extended (PHP), IDE support
    Pake: Written in PHP, Not so popular, PHP-based config
    Quiz: which tool is used by audience?
  • Target: Could depend on other targets, phing <taskname>
    Task: Custom tasks can be implemented, examples
    Types: Reference, FileSet, Property, FileList, Filters

  • list-updates = composer update –dry-run
    security-checker =

  • phpcs with custom configs for php & javascript
  • Regular: Copy config for CI server, warmup cache, install assets & dump them via Assetic
    DB-related: drop & re-create DB, run Doctrine Migrations, load fixtures, validate DB schema. dump schema to DDL file
    twig:lint for Bundles and app/Resources
  • Package: Add version to text file, add DDL schema schema.sql, package app, src, vendors, web to tar.gz
    Deployment (for specific Capifony subtasks: maintenance mode, backup DB, cleat Doctrine cache, cleanup old releases, deploy artifact)
  • Jenkins CI – ex-Hudson CI
    CruiseControl + PHP Under Control
    TeamCity, Bamboo: commercial
    Travis CI, Scrutinizer CI: SAAS
    Quiz: which tool is used by audience?
  • git: disable internal tagging!
    copyartifact: copy artifact from one job to another
    email-ext: sends emails on successful builds, useful for deployment jobs

  • phing
    checkstyle phpcs, hphpa
    dry phpcpd
    jdepend php_depend
    plot phploc using CSV files
    pmd phpmd
    violations aggregates info from phpcs, hphpa, phpmd, phpcpd
    xunit phpunit
    htmlpublisher HTML artifacts
  • build-<branchname>: Builds specific branch (master), Features are verified after merge
    build-package-tag: Parameterizedm Produces .tar.gz artifact from specific Git tag
  • deploy-qa-<branchname>: tar.gz from latest revision of branch, Deploys to QA, Not recommended to have more than one such job (issues with migrations), Workaround: multiple QA or complete DB purge on deploy
    deploy-package-tag: Deploys specific package from build-package-tag to specified environment, Ability to enable/disable maintenance mode and error message via parameters, Email after deployment

  • Previous deployed version examples: <tag>.<build#> = v0.0.3.26, <branchname>-<build#>-<revision>-SNAPSHOT = master-12-7c041a90366ce9d958760094c763d809ffbc629e-SNAPSHOT
  • Capistrano: from Ruby world
    Capifony: Based on Capistrano, Implemented in liip/symfony-rad-edition
    Custom: deb, rpm / VCS update / Rsync, FTP, SCP / Shell script
    Phar: Don’t use WebPhar, Silex does not use it anymore
    Zend Server package: No support for vanilla PHP, Zend Continuous Delivery Blueprint
    PaaS: AWS Elastic Beanstalk, PagodaBox

    Quiz: which tool is used by audience?
  • Capistrano: from Ruby world
    Capifony: Based on Capistrano, Implemented in liip/symfony-rad-edition
    Custom: deb, rpm / VCS update / Rsync, FTP, SCP / Shell script
    Phar: Don’t use WebPhar, Silex does not use it anymore
    Zend Server package: No support for vanilla PHP, Zend Continuous Delivery Blueprint
    PaaS: AWS Elastic Beanstalk, PagodaBox

    Quiz: which tool is used by audience?
  • Based on Capistrano: Supports Capistrano plugins
  • Sometimes there is no access to internet due to security limitations
  • Decreases deployment time: Lot of vendors, Slow internet connection
  • Reproducible: You know what you deploy, You can deploy exactly the same package to multiple environments
    Quick fixes (git commit + git pull) not available
  • pros / contras of maintenance mode

    + users always have good UX (some functionality could be disabled / read only), ~99.999% uptime
    $$$ (implementation, testing, support & maintenance, hardware resources)
  • User Triggers job on Jenkins CI, Choose options (env, maintenance mode)
    Jenkins Executes phing target with additional CLI arguments
    Phing Executes several Capifony commands according to command-line arguments
    Capifony Performs actions on remote machines
  • Maintenance mode maintenance.html in webroot
    Clear Doctrine cache Not for APC cache
    Downloads previous deploy metadata package version, Doctrine Migrations info
  • Restarts services: php-fpm or Apache, Doctrine APC cache is cleared
    Symfony-specific tasks: copy app/config/parameters.yml, doctrine:migrations:migrate, cache:warmup
  • Housekeeping: Perform cleanup for old releases
  • Semi-automatical: from deployment server, usually CI server
    Enable Maintenance: manually via phing
    Manually backup for analysis: DB, current version, Doctrine Migrations status, codebase
  • Switch to previous release: Manually via capifony CLI
    Recover DB: Rollback Doctrine Migrations, Restore DB dump, Custom
    Additional tasks: Restore web server config, Restart service, cache:warmup
    Disable Maintenance Manually via phing
  • Write rollback guide: Step-by-step, Verify it periodically
    Enable monitoring on prod: Zabbix, Pinba, Munin, New Relic, Graylog2
  • Symfony 2 under control

    1. 1. Continuous Integration and Automated Deployments for Symfony-based projects Symfony 2 under control
    2. 2. Whois 2
    3. 3. INTRODUCTION 3
    4. 4. Batteries ARE Included  4
    5. 5. For standard projects Phing Jenkins CI Capifony Quick facts 5
    6. 6. Open Source Bundle Quick facts 6
    7. 7. What is Continuous Integration? 7
    8. 8. Improve quality Understand current situation Automate checklists Notify colleagues How could it help you? 8
    9. 9. composer require "epam/ci- bundle=1.0.*" //update AppKernel app/console epam-ci:init "Acme Demo Project" How to use? 9
    10. 10. •Tweak configuration •Install tools on envs •… •Profit! How to use? 10
    11. 11. BUILD 11
    12. 12. Mmm… Build! 12
    13. 13. Ant Phing Pake Build tools 13
    14. 14. Target •Set of tasks Task •Action Types •Data types Phing Terminology 14
    15. 15. build-epam-ci.xml •Default workflow build.xml •Overwrites Phing build files 15
    16. 16. •Project config •Environment config Phing config files 16
    17. 17. build •dev env •console build-ci •CI env •XML Main Phing Targets 17
    18. 18. package • tar.gz package • DDL dump deploy • packageenv Main Phing Targets 18
    19. 19. All Phing targets? 19
    20. 20. Phing. Want more? 20
    21. 21. clean prepare build-tools-self-update Phing Targets. Special 21
    22. 22. validate install list-updates security-checker Phing Targets. Composer 22
    23. 23. phplint pdepend phpmd Phing Targets. Static analysis 23
    24. 24. apidoc phpcs php-cs-fixer Phing Target. General 24
    25. 25. Phing Targets. General, by Sebastian Bergmann 25
    26. 26. Regular build workflow DB tasks twig:lint Phing Targets. Symfony-specific 26
    27. 27. Package Deployment Phing Targets. Deployment 27
    29. 29. CI servers 29
    30. 30. Open-source Enterprise Jenkins CI overview 30
    31. 31. Tons of plugins PHP Template by Sebastian Bergmann Jenkins CI overview 31
    32. 32. IDE Integration RESTful API Jenkins CI overview 32
    33. 33. Jenkins CI RESTful API 33
    34. 34. git greenballs parameterized- trigger copyartifact email-ext Jenkins Plugins (common) 34
    35. 35. phing checkstyle dry jdepend plot pmd violations xunit htmlpublisher Jenkins Plugins (PHP-specific) 35
    36. 36. build-<branchname> build-package-tag Jenkins Jobs for build 36
    37. 37. deploy-qa-<branchname> deploy-package-tag Jenkins Jobs for deployment 37
    38. 38. Deployed .tar.gz archive Previous deployed version DB dump before deployment Doctrine Migrations info DB schema Jenkins Jobs for deployment. Artifacts Icons by 38
    39. 39. DEPLOYMENT 39
    40. 40. Deployment strategy 40
    41. 41. Custom Zend Server package PaaS Deployment tools 41
    42. 42. Phar Capistrano Capifony Deployment tools 42
    43. 43. Based on Capistrano Symfony 1 & 2 Capifony 43
    44. 44. Multistage Maintenance mode Clustered environments Capifony 44
    45. 45. Directory structure 45
    46. 46. releases/ current/ (symlink) shared/ Directory structure 46
    47. 47. app/config/parameters.yml app/logs web/uploads Directory structure / Shared 47
    48. 48. ln -s not shared across nodes Directory structure / Shared 48
    49. 49. `-- /var/www/ |-- current → /var/www/ |-- releases | `-- 20100512131539 | `-- 20100509150741 | `-- 20100509145325 `-- shared |-- web | `-- uploads |-- logs `-- config `-- parameters.yml Directory structure example from 49
    50. 50. All you need is package capistrano-deploy- strategy-archive Deployment via SCM vs package 50
    51. 51. Deployment via SCM vs package: Github not available? Goodbye, vendors! 51
    52. 52. Decreases deployment time Increases build time Deployment via SCM vs package 52
    53. 53. Reproducible Quick fixes not available Deployment via SCM vs package 53
    54. 54. .tar.gz Optimized autoloader only necessary dirs & files Package contents 54
    55. 55. assets:install assetic:dump version.txt & db-schema.sql Package contents 55
    56. 56. DBDeploy Liquibase Doctrine Migrations Doctrine Fixtures Database Migrations 56
    57. 57. Deployment: Maintenance mode 57
    58. 58. User Jenkins Phing Capifony Capifony & Jenkins CI 58
    59. 59. Maintenance mode on Backup DB Clear Doctrine cache Download previous build metadata Capifony & Phing. Deployment preparations 59
    60. 60. Deploy tar.gz package Restart services Symfony-specific tasks Capifony & Phing. Deployment 60
    61. 61. Maintenance mode off Housekeeping Capifony & Phing. Post-deployment steps 61
    62. 62. Broken build??? 62
    63. 63. Enable Maintenance Manually backup for analysis Rollback is semi-automatic 63
    64. 64. Switch to previous release Additional tasks Disable Maintenance Rollback 64
    65. 65. Write rollback guide Enable monitoring on prod Rollback tips 65
    66. 66. P.S. 66
    67. 67. Build • Static analysis via HHVM • Actually was implemented, but hphpa changed a lot (now it’s wrapper) Deployment • Cronjob / CLI script handling • Web server (Apache, nginx) config manipulations • Ext- and lib- dependency verification via Composer • Custom script execution during deployment What is not implemented yet 67
    68. 68. Questions?