Skip to content

Commit

Permalink
added the drupal:htaccess task and updated the documentation; version…
Browse files Browse the repository at this point in the history
… bumping to 1.0 release
  • Loading branch information
jjohnson-xx committed May 17, 2011
1 parent 1f45648 commit df3fed2
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 76 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
== 1.0.0
* Added the drupal:htaccess task for copying distributed .htaccess files
* Added example Drupal Capfile and staging/production deployment files

== 0.0.20

* Added AAI-hosted Magento script
Expand Down
105 changes: 105 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,97 @@ The capistrano/ash/drupal library takes a hash of Drupal multisites in the follo

where each key is a folder in your @sites@ directory and each value is the URL of the multisite. If you are not using multisites, just exclude the @:multisites@ variable definition.


h3. Capfile

<pre>
<code>
# Capfile
load 'deploy' if respond_to?(:namespace) # cap2 differentiator

# --------------------------------------------
# :application HAS TO BE DEFINED BEFORE
# REQUIRING 'ash/drupal' LIBRARY
# --------------------------------------------
set :application, "bestappever.com"
set :stages, %w(staging production)

# --------------------------------------------
# Define required Gems/libraries
# --------------------------------------------
require 'ash/drupal'

# --------------------------------------------
# Setting defaults
# --------------------------------------------
# IP-address or host's servername
role :app, "bestappever.com"
role :web, "bestappever.com"
role :db, "bestappever.com", :primary => true

# VCS information.
set :repository, "https://svn.example.com/REPO/trunk"
set :scm_username, "SVN_USER"
set :scm_password, proc{Capistrano::CLI.password_prompt("Subversion password for '#{scm_username}':")}

# SSH login credentials
set :user, "SSH_USER"
set :password, proc{Capistrano::CLI.password_prompt("SSH password for '#{user}':")}

# Deploy to file path
set(:deploy_to) { "/var/www/#{application}/#{stage}" }

# Database credentials
set :dbuser, "DB_USER_NAME"

# Define which files or directories you want to exclude from being backed up
set(:backup_exclude) { [ "var/" ] }


# --------------------------------------------
# Drupal Multi-Sites
# --------------------------------------------
# Setting which folder in the sites directory to use
set :multisites, {
'bestapp' => 'bestappever.com',
}


# --------------------------------------------
# Callbacks - Set Before/After Precedence
# --------------------------------------------
before "deploy:update_code", "deploy:setup_backup"
after "deploy:setup_backup", "backup"
</code>
</pre>

h3. config/deploy/staging.rb

<pre>
<code>
# config/deploy/staging.rb
# Database Name
set :dbname, "DB_NAME"

# Backups Path (/var/www/#{application}/staging/backups)
set :backups_path, "#{deploy_to}/backups"
</code>
</pre>

h3. config/deploy/production.rb

<pre>
<code>
# config/deploy/production.rb
# Database Name
set :dbname, "DB_NAME"

# Backups Path (/var/www/#{application}/production/backups)
set :backups_path, "#{deploy_to}/backups"
</code>
</pre>


h2. Deploying Zend or Zend/Doctrine example

h3. Capfile
Expand Down Expand Up @@ -88,6 +179,13 @@ h3. config/deploy/staging.rb
<pre>
<code>
# config/deploy/staging.rb

# Deploy site using Capistrano
#
# Usage:
# cap staging deploy:setup
# cap staging deploy

# Database Name
set :dbname, "DB_NAME"

Expand All @@ -101,6 +199,13 @@ h3. config/deploy/production.rb
<pre>
<code>
# config/deploy/production.rb

# Deploy site using Capistrano
#
# Usage:
# cap production deploy:setup
# cap production deploy

# Database Name
set :dbname, "DB_NAME"

Expand Down
156 changes: 80 additions & 76 deletions lib/ash/drupal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,115 +7,119 @@

configuration.load do

# --------------------------------------------
# Setting defaults
# --------------------------------------------
proc{_cset( :multisites, {"default" => "#{application}"} )}
set :drush_bin, "drush"
# --------------------------------------------
# Setting defaults
# --------------------------------------------
proc{_cset( :multisites, {"default" => "#{application}"} )}
set :drush_bin, "drush"

# --------------------------------------------
# Calling our Methods
# --------------------------------------------
after "deploy:setup", "deploy:setup_shared"
after "deploy:finalize_update", "ash:fixperms"
after "ash:fixperms", "drupal:protect"
after "deploy:symlink", "drupal:symlink"
after "deploy", "drupal:clearcache"
after "deploy", "deploy:cleanup"
# --------------------------------------------
# Calling our Methods
# --------------------------------------------
after "deploy:setup", "deploy:setup_shared"
after "deploy:finalize_update", "ash:fixperms"
after "ash:fixperms", "drupal:protect"
after "deploy:symlink", "drupal:symlink"
after "deploy", "drupal:clearcache"
after "deploy", "drupal:htaccess"
after "deploy", "deploy:cleanup"

# --------------------------------------------
# Overloaded Methods
# --------------------------------------------
namespace :deploy do
# --------------------------------------------
# Overloaded Methods
# --------------------------------------------
namespace :deploy do
desc "Setup shared application directories and permissions after initial setup"
task :setup_shared, :roles => :web do
# remove Capistrano specific directories
run "rm -Rf #{shared_path}/log"
run "rm -Rf #{shared_path}/pids"
run "rm -Rf #{shared_path}/system"
# remove Capistrano specific directories
run "rm -Rf #{shared_path}/log"
run "rm -Rf #{shared_path}/pids"
run "rm -Rf #{shared_path}/system"

# create shared directories
multisites.each_pair do |folder, url|
run "mkdir -p #{shared_path}/#{url}/files"
end
# create shared directories
multisites.each_pair do |folder, url|
run "mkdir -p #{shared_path}/#{url}/files"
end

# set correct permissions
run "chmod -R 777 #{shared_path}/*"
# set correct permissions
run "chmod -R 777 #{shared_path}/*"
end

desc "[internal] Touches up the released code. This is called by update_code after the basic deploy finishes."
task :finalize_update, :except => { :no_release => true } do
# remove shared directories
multisites.each_pair do |folder, url|
run "mv #{latest_release}/sites/#{folder} #{latest_release}/sites/#{url}"
run "rm -Rf #{latest_release}/sites/#{url}/files"
end
# remove shared directories
multisites.each_pair do |folder, url|
run "mv #{latest_release}/sites/#{folder} #{latest_release}/sites/#{url}"
run "rm -Rf #{latest_release}/sites/#{url}/files"
end
end

namespace :web do
desc "Disable the application and show a message screen"
task :disable do
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{latest_release} vset --yes site_offline 1"
end
desc "Disable the application and show a message screen"
task :disable do
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{latest_release} vset --yes site_offline 1"
end
end

desc "Enable the application and remove the message screen"
task :enable do
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{latest_release} vdel --yes site_offline"
end
desc "Enable the application and remove the message screen"
task :enable do
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{latest_release} vdel --yes site_offline"
end
end
end
end
end

namespace :backup do
desc "Perform a backup of database files"
task :db, :roles => :db do
puts "Backing up the database now and putting dump file in the previous release directory"
multisites.each_pair do |folder, url|
# define the filename (include the current_path so the dump file will be within the dirrectory)
filename = "#{current_path}/#{folder}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
# dump the database for the proper environment
run "#{drush_bin} -l #{url} -r #{current_path} sql-dump | gzip -c --best > #{filename}"
namespace :backup do
desc "Perform a backup of database files"
task :db, :roles => :db do
puts "Backing up the database now and putting dump file in the previous release directory"
multisites.each_pair do |folder, url|
# define the filename (include the current_path so the dump file will be within the dirrectory)
filename = "#{current_path}/#{folder}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
# dump the database for the proper environment
run "#{drush_bin} -l #{url} -r #{current_path} sql-dump | gzip -c --best > #{filename}"
end
end
end
end

# --------------------------------------------
# Drupal-specific methods
# --------------------------------------------
namespace :drupal do
# --------------------------------------------
# Drupal-specific methods
# --------------------------------------------
namespace :drupal do
desc "Symlink shared directories"
task :symlink, :except => { :no_release => true } do
multisites.each_pair do |folder, url|
run "ln -nfs #{shared_path}/#{url}/files #{current_release}/sites/#{url}/files"
run "ln -nfs #{latest_release}/sites/#{url}/settings.php.#{stage} #{latest_release}/sites/#{url}/settings.php"
run "#{drush_bin} -l #{url} -r #{current_path} vset --yes file_directory_path sites/#{url}/files"
end
multisites.each_pair do |folder, url|
run "ln -nfs #{shared_path}/#{url}/files #{current_release}/sites/#{url}/files"
run "ln -nfs #{latest_release}/sites/#{url}/settings.php.#{stage} #{latest_release}/sites/#{url}/settings.php"
run "#{drush_bin} -l #{url} -r #{current_path} vset --yes file_directory_path sites/#{url}/files"
end
end

desc "Replace local database paths with remote paths"
task :updatedb, :except => { :no_release => true } do
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{current_path} sqlq \"UPDATE {files} SET filepath = REPLACE(filepath,'sites/#{folder}/files','sites/#{url}/files');\""
end
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{current_path} sqlq \"UPDATE {files} SET filepath = REPLACE(filepath,'sites/#{folder}/files','sites/#{url}/files');\""
end
end

desc "Clear all Drupal cache"
task :clearcache, :except => { :no_release => true } do
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{current_path} cache-clear all"
end
multisites.each_pair do |folder, url|
run "#{drush_bin} -l #{url} -r #{current_path} cache-clear all"
end
end

desc "Protect system files"
task :protect, :except => { :no_release => true } do
multisites.each_pair do |folder, url|
run "chmod 644 #{latest_release}/sites/#{url}/settings.php*"
end
multisites.each_pair do |folder, url|
run "chmod 644 #{latest_release}/sites/#{url}/settings.php*"
end
end

end


desc 'Copy over htaccess file'
task :htaccess do
run "cp #{latest_release}/htaccess.dist #{latest_release}/.htaccess"
end
end
end

0 comments on commit df3fed2

Please sign in to comment.