Created
May 2, 2012 17:21
-
-
Save slantview/2578423 to your computer and use it in GitHub Desktop.
Capistrano Deployment for Drupal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| load 'deploy' if respond_to?(:namespace) # cap2 differentiator | |
| Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | |
| load 'config/deploy.rb' | |
| require 'capistrano/ext/multistage' | |
| namespace :deploy do | |
| # Overwritten to provide flexibility for people who aren't using Rails. | |
| desc "Prepares one or more servers for deployment." | |
| task :setup, :roles => :web, :except => { :no_release => true } do | |
| dirs = [deploy_to, releases_path, shared_path] | |
| domains.each do |domain| | |
| dirs += [shared_path + "/#{domain}/files"] | |
| end | |
| dirs += %w(system).map { |d| File.join(shared_path, d) } | |
| run "umask 02 && mkdir -p #{dirs.join(' ')}" | |
| end | |
| desc "Create settings.php in shared/config" | |
| task :after_setup, :roles => :web do | |
| configuration = <<-EOF | |
| <?php | |
| $db_url = 'mysql://username:password@localhost/databasename'; | |
| $db_prefix = ''; | |
| EOF | |
| domains.each do |domain| | |
| put configuration, "#{deploy_to}/#{shared_dir}/#{domain}/settings.php" | |
| end | |
| end | |
| task :update_code, :roles => :web, :except => { :no_release => true } do | |
| on_rollback { run "rm -rf #{release_path}; true" } | |
| strategy.deploy! | |
| finalize_update | |
| end | |
| desc "link file dirs" | |
| after 'deploy:update_code', :roles => :web do | |
| domains.each do |domain| | |
| # link settings file | |
| run "ln -nfs #{deploy_to}/#{shared_dir}/#{domain}/settings.php #{release_path}/sites/#{domain}/settings.php" | |
| # remove any link or directory that was exported from SCM, and link to remote Drupal filesystem | |
| run "rm -rf #{release_path}/sites/#{domain}/files" | |
| run "ln -nfs #{deploy_to}/#{shared_dir}/#{domain}/files #{release_path}/sites/#{domain}/files" | |
| end | |
| end | |
| task :create_symlink, :roles => :web, :except => { :no_release => true } do | |
| on_rollback do | |
| if previous_release | |
| run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" | |
| else | |
| logger.important "no previous release to rollback to, rollback of symlink skipped" | |
| end | |
| end | |
| run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}" | |
| end | |
| # desc '[internal] Touches up the released code.' | |
| task :finalize_update, :roles => :web, :except => { :no_release => true } do | |
| run "chmod -R g+w #{release_path}" | |
| end | |
| desc "Flush the Drupal cache system." | |
| task :cacheclear, :roles => :web do | |
| domains.each do |domain| | |
| run "#{drush} --uri=#{domain} cache-clear all" | |
| end | |
| end | |
| namespace :web do | |
| desc "Set Drupal maintainance mode to online." | |
| task :enable do | |
| domains.each do |domain| | |
| run "#{drush} --uri=#{domain} vset --always-set maintenance_mode 0" | |
| run "#{drush} --uri=#{domain} cache-clear all" | |
| end | |
| end | |
| desc "Set Drupal maintainance mode to off-line." | |
| task :disable do | |
| domains.each do |domain| | |
| run "#{drush} --uri=#{domain} vset --always-set maintenance_mode 1" | |
| run "#{drush} --uri=#{domain} cache-clear all" | |
| end | |
| end | |
| end | |
| after "deploy", "deploy:cacheclear" | |
| after "deploy", "deploy:cleanup" | |
| # Each of the following tasks are Rails specific. They're removed. | |
| task :migrate do | |
| end | |
| task :migrations do | |
| end | |
| task :cold do | |
| end | |
| task :start do | |
| end | |
| task :stop do | |
| end | |
| task :restart do | |
| end | |
| end | |
| desc "Download a backup of the database(s) from the given stage." | |
| task :download_db, :roles => :db, :only => { :primary => true } do | |
| domains.each do |domain| | |
| filename = "#{domain}_#{stage}.sql" | |
| run "#{drush} --uri=#{domain} sql-dump --structure-tables-key=common > /tmp/#{filename}" | |
| download("/tmp/#{filename}", "#{filename}", :via=> :scp) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### This file contains project-specific settings ### | |
| # The project name. | |
| set :application, "application" | |
| # List the Drupal multi-site folders. Use "default" if no multi-sites are installed. | |
| set :domains, ["default"] | |
| # Set the repository type and location to deploy from. | |
| set :scm, :git | |
| set :repository, "[email protected]:project.git" | |
| # Use a remote cache to speed things up | |
| set :deploy_via, :remote_cache | |
| # Multistage support - see config/sites/[STAGE].rb for specific configs | |
| set :default_stage, "production" | |
| set :stages, %w(production development qa) | |
| # Generally don't need sudo for this deploy setup | |
| set :use_sudo, false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add ssh private key from deployment user here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add public key from deployment user here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### This file contains stage-specific settings ### | |
| # Set the deployment directory on the target hosts. | |
| set :deploy_to, "/var/www/html/application" | |
| # Set the branch | |
| set :branch, "master" | |
| # The hostnames to deploy to. | |
| role :web, "192.168.100.37" | |
| # Specify one of the web servers to use for database backups or updates. | |
| # This server should also be running Drupal. | |
| role :db, "192.168.100.37", :primary => true | |
| # The username on the target system, if different from your local username | |
| ssh_options[:user] = 'appname-deploy' | |
| # The path to drush | |
| set :drush, "/bin/env drush" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### This file contains stage-specific settings ### | |
| # Set the deployment directory on the target hosts. | |
| set :deploy_to, "/var/www/html/application" | |
| # Set the branch | |
| set :branch, "master" | |
| # The hostnames to deploy to. | |
| role :web, "192.168.100.37" | |
| # Specify one of the web servers to use for database backups or updates. | |
| # This server should also be running Drupal. | |
| role :db, "192.168.100.37", :primary => true | |
| # The username on the target system, if different from your local username | |
| ssh_options[:user] = 'appname-deploy' | |
| # The path to drush | |
| set :drush, "/bin/env drush" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ### This file contains stage-specific settings ### | |
| # Set the deployment directory on the target hosts. | |
| set :deploy_to, "/var/www/html/application" | |
| # Set the branch | |
| set :branch, "master" | |
| # The hostnames to deploy to. | |
| role :web, "192.168.100.37" | |
| # Specify one of the web servers to use for database backups or updates. | |
| # This server should also be running Drupal. | |
| role :db, "192.168.100.37", :primary => true | |
| # The username on the target system, if different from your local username | |
| ssh_options[:user] = 'appname-deploy' | |
| # The path to drush | |
| set :drush, "/bin/env drush" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment