Automated Drupal deployment with Git & Capistrano Farez Rahman Freelance Drupal developer Co-founder: OnSavvy.com
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
Show of hands please... Some sort of automated deployment process Git and Capistrano Git only + SSH FTP/SFTP Aegir? Drush? Pantheon? No idea!
Goal Automated deployment: reduce manual human error Anyone can deploy: startup = speed is important
Wins... Reduced multiple steps turned into one step ssh, git pull, update db, revert features, clear cache... “cap deploy”
Wins... Less steps missed out due to human error
Wins... No manual SSH into server great for non-geeks
Wins... Doing more for each deploy just add to deploy script
Wins... Quick to rollback “cap deploy:rollback”
Wins Less boring
Costs... Setup costs... capistrano, ruby training for other team members
Costs Security potential to run malicious commands on server from developer’s machine
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)
Capistrano Ruby Gem Remote control for server commands No server-side installations Runs over SSH
Our setup
CapDrupal (Ruby Gem) Drupal-specific Capistrano tasks We use modified version of CapDrupal There are others (cap-drupal, capistrano- drupal...)
CapDrupal (Ruby Gem)...
Drush CapDrupal needs Drush on your server Capistrano itself doesn’t.. but no Drush = limited options
How to deploy 1. Make local changes 2. git commit and push 3. $ “cap deploy” That’s it
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
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
Before “cap deploy” current -> releases/20130805211651 releases/ 20130801135258 20130805211547 20130805211651 shared/ cached-copy/ files/ settings.php
After “cap deploy” current -> releases/20130805212640 (points to new clone) releases/ 20130801135258 20130805211547 20130805211651 20130805212640 <- new git clone shared/ cached-copy/ files/ settings.php
Local directory structure app/ <- drupal root config/ deploy.rb <- project specific settings dev.rb <- site specific settings live.rb Capfile
deploy.rb
Local directory structure app/ <- drupal root config/ deploy.rb <- project specific settings dev.rb <- site specific settings live.rb Capfile
dev.rb
Rolling back “cap deploy:rollback” Doesn't rollback database But can create custom cap tasks to do that
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
All Capistrano tasks “cap -T”
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
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
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

Automated Drupal deployment with Git and Capistrano