Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Introduction

Capistrano is a Ruby tool that can be used to deploy Drupal site to multiple servers. It also allows you to run scripts on remote servers easily. Combined with drush it becomes a very good tool for handling Drupal sites.

You'll end up working on the site on a development server - installing modules manually or with drush, enabling them, etc. You can go to your development site with your browser and play around. You'll try to make sure all the configuration information is exported as code using features, installation profiles, etc. You'll be able to import the database from staging or production servers and try things out. Everything (except the database) will be tracked with git.

When you want to move a site to the staging server, you go to the command line on your development server and say

Code Block

bash> cap staging deploy

This goes to the site on the staging server, puts the site offline, backs up the database, moves a copy of the site to a new revision directory, points the domain name at the new revision, sets up some symbolic links to files, private_files, settings.php, does an update.php in case modules changed, reverts all the features in case they changed, makes a new git tag for the deploy, clears the cache, puts the site back on line, and a few more things.

If something screws up, you can say

Code Block

bash> cap staging deploy:rollback

and the process is reversed, including restoring the database to it's original state.

Setting this up requires making a git repository for each site, creating a specific directory structure for the site on your development server, setting up a web accessible symbolic link, and tweaking the Capistrano configuration files to describe your staging & production servers. Through a combination of Puppet and Capistrano the staging and production servers get set up automatically.

Your  Your Development Environment

Setup   
I had a lot of trouble with online recipes not matching the version of Capistrano I had. I settled on Capistrano v2.15.5 since that's what the Blacklight project is using. (capistrano-ext hasn't changed since 2008)
You'll Ruby, Capistrano, PHP, MySQL, Git, drush, and a server to run the Drupal site.

...

Set up a git repository for the site on https://git.library.cornell.edu/ - example https://git.library.cornell.edu/featureserver_test_library_cornell_edumkdiredu

Code Block

mkdir featureserver_test_library_cornell_edu

...

Code Block
cd featureserver_test_library_cornell_edu
git init
touch README.txt
git add README.txt
git commit -m 'first commit'
git remote add origin git@git.library.cornell.edu:featureserver_test_library_cornell_edu.git
git push -u origin master

...