Skip to content

Instantly share code, notes, and snippets.

@diasjorge
Created February 4, 2011 12:59
Show Gist options
  • Save diasjorge/811079 to your computer and use it in GitHub Desktop.
Save diasjorge/811079 to your computer and use it in GitHub Desktop.
Drupal deployment strategy
# Requirements
# - You need drush installed on your project
# Current Features:
# - Revert all features
# - Backup database prior to deploy
# - Handle sites/default/files across releases
# - Clear cache
# TODO:
# - Automatic database updates
set :application, "YOUR APP"
set :deploy_via, :remote_cache
set :scm, :git
set :repository, "GIT_REPO_URL"
set :branch, "master"
set :user, "DEPLOY USER NAME"
set :use_sudo, false # Your deploy user should not need sudo permission
ssh_options[:forward_agent] = true
role :web, "www.example.com" # Your HTTP server, Apache/etc
role :app, "www.example.com" # This may be the same as your `Web` server
role :db, "www.example.com", :primary => true
# Drupal Customizations
set :normalize_asset_timestamps, false
set :site_uri, "SITE URI TO USE WITH DRUSH"
set :drush_cmd, "drush --uri=#{site_uri}"
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart do ; end
desc "Backup the DB before this update"
task :backup_db, :roles => :db do
run "cd #{previous_release} && #{drush_cmd} sql-dump > dump.sql"
end
# Your default/files should not be under scm, but we'll help if you do
desc "Move default drupal files if they exist and symlink to shared path"
task :move_default_files, :roles => :app do
run <<-CMD
if [ -d #{release_path}/sites/default/files ]; then \
cd #{release_path}/sites/default && \
rsync -avz files/ #{shared_path}/files && \
rm -rf files; \
fi; \
ln -nsf #{shared_path}/files .
CMD
end
desc "Revert all features"
task :revert_features, :roles => :db do
run "cd #{current_path} && #{drush_cmd} features-revert-all" do |ch, stream, out|
puts out if out =~ /The following/
ch.send_data "y\n" if out =~ /Do you really want to continue?/
end
end
desc "Clear all cache"
task :clear_cache, :roles => :app do
run "cd #{current_path} && #{drush_cmd} cache-clear all"
end
end
after "deploy:update_code", "deploy:backup_db"
before "deploy:symlink", "deploy:move_default_files"
before "deploy:symlink", "deploy:revert_features"
before "deploy:symlink", "deploy:clear_cache"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment