Automated Drupal deployment with Git and Capistrano

7,509 views
7,181 views

Published on

How we automated our Drupal deployment process at onsavvy.com with Git and Capistrano. First presented at Drupal Show and Tell, 15 August 2013, London.

Published in: Technology
4 Comments
10 Likes
Statistics
Notes
No Downloads
Views
Total views
7,509
On SlideShare
0
From Embeds
0
Number of Embeds
88
Actions
Shares
0
Downloads
25
Comments
4
Likes
10
Embeds 0
No embeds

No notes for slide

Automated Drupal deployment with Git and Capistrano

  1. 1. Automated Drupal deployment with Git & Capistrano Farez Rahman Freelance Drupal developer Co-founder: OnSavvy.com
  2. 2. About this session Git+Capistrano for deployment Mainly Capistrano Overview - not too detailed Input/feedback/questions from you guys Lots of info online - links at the end
  3. 3. Show of hands please... Some sort of automated deployment process Git and Capistrano Git only + SSH FTP/SFTP Aegir? Drush? Pantheon? No idea!
  4. 4. Goal Automated deployment: reduce manual human error Anyone can deploy: startup = speed is important
  5. 5. Wins... Reduced multiple steps turned into one step ssh, git pull, update db, revert features, clear cache... “cap deploy”
  6. 6. Wins... Less steps missed out due to human error
  7. 7. Wins... No manual SSH into server great for non-geeks
  8. 8. Wins... Doing more for each deploy just add to deploy script
  9. 9. Wins... Quick to rollback “cap deploy:rollback”
  10. 10. Wins Less boring
  11. 11. Costs... Setup costs... capistrano, ruby training for other team members
  12. 12. Costs Security potential to run malicious commands on server from developer’s machine
  13. 13. Why capistrano Looked at a few options (git hooks, Jenkins, capistrano) capistrano - simple, does the job for us Drupal deploy scripts available (capdrupal, capistrano-drupal)
  14. 14. Capistrano Ruby Gem Remote control for server commands No server-side installations Runs over SSH
  15. 15. Our setup
  16. 16. CapDrupal (Ruby Gem) Drupal-specific Capistrano tasks We use modified version of CapDrupal There are others (cap-drupal, capistrano- drupal...)
  17. 17. CapDrupal (Ruby Gem)...
  18. 18. Drush CapDrupal needs Drush on your server Capistrano itself doesn’t.. but no Drush = limited options
  19. 19. How to deploy 1. Make local changes 2. git commit and push 3. $ “cap deploy” That’s it
  20. 20. What “cap deploy” does SSH into server Takes site offline Backup of db (using drush & backup_migrate) Clones latest revision from dev branch Points site root to that latest clone Runs update db Reverts features Clears cache Puts site back online
  21. 21. Directory structure on server current -> releases/20130805211651 (symlink) releases/ 20130801135258 20130805211547 20130805211651 shared/ cached-copy/ files/ settings.php NB: running “cap deploy:setup” creates the dir structure
  22. 22. Before “cap deploy” current -> releases/20130805211651 releases/ 20130801135258 20130805211547 20130805211651 shared/ cached-copy/ files/ settings.php
  23. 23. After “cap deploy” current -> releases/20130805212640 (points to new clone) releases/ 20130801135258 20130805211547 20130805211651 20130805212640 <- new git clone shared/ cached-copy/ files/ settings.php
  24. 24. Local directory structure app/ <- drupal root config/ deploy.rb <- project specific settings dev.rb <- site specific settings live.rb Capfile
  25. 25. deploy.rb
  26. 26. Local directory structure app/ <- drupal root config/ deploy.rb <- project specific settings dev.rb <- site specific settings live.rb Capfile
  27. 27. dev.rb
  28. 28. Rolling back “cap deploy:rollback” Doesn't rollback database But can create custom cap tasks to do that
  29. 29. Customisations to Capdrupal “backup db”, “update db”, “revert features” = not relevant when only updating CSS so we removed them from deploy task can be run by themselves when needed
  30. 30. All Capistrano tasks “cap -T”
  31. 31. Potential improvements Create backups of db, that can be rolled back (e.g new copy of db and settings.php for each new deploy) Fully automated deployment, continuous integration
  32. 32. References YouTube: - Simple and powerful site deployment with capistrano - by Kim Pepper - http://youtu.be/ulK-lhv8eI0 - DrupalCon Munich 2012: Deploy with Capistrano - by Michael Priest - http://youtu.be/fvkiWfjmKQ4 Github: https://github.com/antistatique/capdrupal https://github.com/previousnext/capistrano-drupal https://github.com/capistrano Google capistrano drupal
  33. 33. Feel free to get in touch Farez Rahman slideshare.net/onsavvy onsavvy.com/profile/farez-rahman d.o: user/261497 Twitter: farez farez @ redkeydigital.com

×