Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using Capifony for Symfony apps deployment (updated)

2,261 views

Published on

My presentation from the talk about Symfony apps deployment I gave at Kaunas PHP meetup.
Capistrano is an open source tool for running scripts on multiple servers. Capifony - set of instructions called “recipes” for Symfony applications deployment.
Built to make your job a lot easier.

Published in: Technology
  • Be the first to comment

Using Capifony for Symfony apps deployment (updated)

  1. 1. Using Capifony for Symfony apps deployment Žilvinas Kuusas KaunasPHP v.23, 2015-02-11 / http://kaunasphp.lt
  2. 2. Žilvinas Kuusas lead developer at Estina / iSign.io t: @kuusas e: zilvinas@kuusas.lt Who am I?
  3. 3. What I do? I write code. Co-organize: NoTrollsAllowed.com VilniusPHP.lt Symfony.lt
  4. 4. Symfony app deployment
  5. 5. Deployment... Code ● FTP ● $ vim ● $ rsync ● $ git pull Database ● Manually manage DB fields ● phpMyAdmin ● $ mysql < changes.sql Infrastructure...
  6. 6. Symfony - heavy Many many deployment steps: ● git pull ● assets:install ● assetic:dump ● doctrine:migrations:migrate ● cache:clear ● cache:warmup ● restart some services ● ...
  7. 7. What if … … you forgot one of the steps? Forgot to clear cache...
  8. 8. Don’t Repeat Yourself AUTOMATE!
  9. 9. Goals for solid deployment ● One-click deployment ● Deploy in one transaction ● Rollback ● Automated tasks ● Notifications ● 0 downtime ● Confidence
  10. 10. Capistrano Capifony
  11. 11. What Capistrano is? ● Capistrano is an open source tool for running scripts on multiple servers ● Primary use - application deployment ● Capifony - set of instructions called “recipes” for Symfony applications deployment ● Built to make your job a lot easier
  12. 12. Why Capifony? ● Fully supports Symfony features ● Actively maintained since 2009 ● 6 active contributors ● >100 total ● last commit 16 days ago
  13. 13. What do we need? ● Symfony2 application ● Capifony ● SSH access to server (ssh-key recommended) ● Minor changes in web server configuration
  14. 14. Folder structure on web server
  15. 15. Web server configuration
  16. 16. Setup $ sudo gem install capifony $ cd /path/to/your/project $ capifony .
  17. 17. $ capifony .
  18. 18. $ vi app/config/deploy.rb
  19. 19. $ vi app/config/deploy.rb
  20. 20. $ cap deploy
  21. 21. $ cap deploy
  22. 22. Main deployment commands $ cap deploy … $ cap deploy:migrations ... $ cap deploy:rollback
  23. 23. Deployment strategies deployment > scm > production
  24. 24. Deployment strategies scm > deployment > production
  25. 25. Behind scenes
  26. 26. What else Capifony can do? ● Execute Symfony commands on server ● Execute shell commands on server ● Dump remote database and download ● Tail logs ● Turn on/off maintenance page
  27. 27. $ cap -vT # Lists all tasks available $ cap deploy:check $ cap database:copy:to_local $ cap deploy:cold $ cap deploy:pending $ cap deploy:web:disable $ cap deploy:web:enable $ cap symfony:logs:tail $ cap symfony ...
  28. 28. Database deployment To deploy database schema updates in... ● SAFE ● EASY ● STANDARDIZED way… Use database migrations!
  29. 29. DoctrineMigrationsBundle
  30. 30. $ app/console doctrine:migrations:diff
  31. 31. Deploying with migrations: $ cap deploy:migrations Rolling-back migrations: $ cap symfony -S task_arguments="doctrine: migrations:migrate 20150205170707 --no-interaction" $ cap deploy:migrations
  32. 32. OPcache ● Create temp file accessible via www ● Make curl request (x5) ● Remove file Capistrano recipe for that: https://github.com/occitech/capistrano-recipes/blob/master/Opcache-Recipe.rb
  33. 33. Keeping Symfony sessions
  34. 34. Multistage extension Enables deployment to multiple servers $ cap STAGE_NAME deploy Multistage extension: https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension
  35. 35. Deploying release package ● CI server builds release package (zip) ● Capifony deploys ● Only in Capistrano v2.15 Capistrano deploy strategy called “archive”: https://github.com/sorccu/capistrano-deploy-strategy-archive
  36. 36. Symfony related configuration
  37. 37. Extending Capistrano It’s Ruby!
  38. 38. Override Capistrano recipes
  39. 39. Listen to events
  40. 40. Debugging
  41. 41. $ cap deploy -d
  42. 42. cap deploy:migrations -s branch=master cap deploy:migrations -S my_var=value Arguments in CLI
  43. 43. Other deployment tools ● Fabric (Python) ● Idephix ● Magellanes ● Deployer ● Laravel / Envoy ● Rocketeer ● Ansible + Tower
  44. 44. Final thoughts Don’t use FTP
  45. 45. Final thoughts Don’t repeat yourself
  46. 46. Final thoughts AUTOMATE
  47. 47. Questions?
  48. 48. AČIŪ Credits for image authors. “what if…” gif taken from devopsreactions.tumblr.com, deployment strategies - from capifony.org. Couldn’t find the real authors of lizzard and kitty - so if its your’s - THANK YOU.

×