Permalink
Browse files

Merge branch 'release/v1.4.1' into develop

2 parents 6fcea3f + 02294ce commit 1f45d2ed4dabbcf4cd963706306d3ea1a8701b45 @jjohnson-xx jjohnson-xx committed Mar 27, 2014
Showing with 232 additions and 79 deletions.
  1. +8 −4 Rakefile
  2. +1 −1 VERSION
  3. +17 −15 capistrano-ash.gemspec
  4. +96 −16 lib/ash/base.rb
  5. +2 −2 lib/ash/common.rb
  6. +40 −9 lib/ash/drupal.rb
  7. +12 −32 lib/ash/magento.rb
  8. +41 −0 lib/ash/performance.rb
  9. +15 −0 lib/ash/zend_doctrine.rb
View
@@ -11,10 +11,14 @@ begin
gemspec.homepage = "https://github.com/augustash/capistrano-ash"
gemspec.authors = ["August Ash"]
# Gem dependencies
- gemspec.add_dependency('capistrano', '~> 2.15.0')
- gemspec.add_dependency('capistrano-ext')
- gemspec.add_dependency('railsless-deploy')
- gemspec.add_dependency('capistrano_colors')
+ gemspec.add_dependency('capistrano', '~> 2.15.5')
+ gemspec.add_dependency('capistrano-ext', '~> 1.2')
+ gemspec.add_dependency('railsless-deploy', '~> 1.1')
+ gemspec.add_dependency('capistrano_colors', '~> 0.5')
+
+ # Net-SSH issues
+ # see https://github.com/capistrano/capistrano/issues/927
+ gemspec.add_dependency('net-ssh', '2.7.0')
end
rescue LoadError
View
@@ -1 +1 @@
-1.4.0
+1.4.1
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = "capistrano-ash"
- s.version = "1.3.2"
+ s.version = "1.4.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["August Ash"]
@@ -39,21 +39,23 @@ Gem::Specification.new do |s|
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<capistrano>, ["~> 2.15.0"])
- s.add_runtime_dependency(%q<capistrano-ext>, [">= 0"])
- s.add_runtime_dependency(%q<railsless-deploy>, [">= 0"])
- s.add_runtime_dependency(%q<capistrano_colors>, [">= 0"])
- else
- s.add_dependency(%q<capistrano>, ["~> 2.15.0"])
- s.add_dependency(%q<capistrano-ext>, [">= 0"])
- s.add_dependency(%q<railsless-deploy>, [">= 0"])
- s.add_dependency(%q<capistrano_colors>, [">= 0"])
+ s.add_runtime_dependency(%q<capistrano>, ["~> 2.15.5"])
+ s.add_dependency(%q<capistrano-ext>, ["~> 1.2"])
+ s.add_dependency(%q<railsless-deploy>, ["~> 1.1"])
+ s.add_dependency(%q<capistrano_colors>, ["~> 0.5"])
+ s.add_dependency(%q<net-ssh>, ['2.7.0'])
+ else
+ s.add_dependency(%q<capistrano>, ["~> 2.15.5"])
+ s.add_dependency(%q<capistrano-ext>, ["~> 1.2"])
+ s.add_dependency(%q<railsless-deploy>, ["~> 1.1"])
+ s.add_dependency(%q<capistrano_colors>, ["~> 0.5"])
+ s.add_dependency(%q<net-ssh>, ['2.7.0'])
end
else
- s.add_dependency(%q<capistrano>, ["~> 2.15.0"])
- s.add_dependency(%q<capistrano-ext>, [">= 0"])
- s.add_dependency(%q<railsless-deploy>, [">= 0"])
- s.add_dependency(%q<capistrano_colors>, [">= 0"])
+ s.add_dependency(%q<capistrano>, ["~> 2.15.5"])
+ s.add_dependency(%q<capistrano-ext>, ["~> 1.2"])
+ s.add_dependency(%q<railsless-deploy>, ["~> 1.1"])
+ s.add_dependency(%q<capistrano_colors>, ["~> 0.5"])
+ s.add_dependency(%q<net-ssh>, ['2.7.0'])
end
end
-
View
@@ -39,10 +39,11 @@
set :dbpass, proc{Capistrano::CLI.password_prompt("Database password for '#{dbuser}':")}
set :dbname, proc{text_prompt("Database name: ")}
_cset :mysqldump, "mysqldump"
- _cset :dump_options, "--single-transaction --create-options --quick --triggers --routines"
+ _cset :dump_options, "--single-transaction --create-options --quick --triggers --routines --force --opt --skip-lock-tables"
+ _cset :ignore_tables, []
# Source Control
- set :group_writable, false
+ # set :group_writable, false
set :use_sudo, false
set :scm, :git
set :git_enable_submodules, 1 if fetch(:scm, :git)
@@ -59,6 +60,13 @@
# phpMyAdmin version
set :pma_version, "3.4.5"
+ # FIX capistrano 2.15.4+ use of `try_sudo` with capture commands (shouldn't need sudo for `ls` and `cat` commands)
+ set(:releases) { capture("ls -x #{releases_path}", :except => { :no_release => true }).split.sort }
+ set(:current_revision) { capture("cat #{current_path}/REVISION", :except => { :no_release => true }).chomp }
+ set(:latest_revision) { capture("cat #{current_release}/REVISION", :except => { :no_release => true }).chomp }
+ set(:previous_revision) { capture("cat #{previous_release}/REVISION", :except => { :no_release => true }).chomp if previous_release }
+
+
# Backups Path
_cset(:backups_path) { File.join(deploy_to, "backups") }
_cset(:tmp_backups_path) { File.join("#{backups_path}", "tmp") }
@@ -110,7 +118,8 @@
dirs = [deploy_to, releases_path, shared_path]
dirs += shared_children.map { |d| File.join(shared_path, d.split('/').last) }
run "mkdir -p #{dirs.join(' ')}"
- run "chmod 755 #{dirs.join(' ')}" if fetch(:group_writable, true)
+ run "#{try_sudo} chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
+ # run "chmod 755 #{dirs.join(' ')}" if fetch(:group_writable, true)
end
desc "Setup shared application directories and permissions after initial setup"
@@ -132,6 +141,33 @@
end
desc <<-DESC
+ Updates the symlink to the most recently deployed version. Capistrano works \
+ by putting each new release of your application in its own directory. When \
+ you deploy a new version, this task's job is to update the `current' symlink \
+ to point at the new version. You will rarely need to call this task \
+ directly; instead, use the `deploy' task (which performs a complete \
+ deploy, including `restart') or the 'update' task (which does everything \
+ except `restart').
+
+ AAI OVERRIDES:
+ removes use of try_sudo with symlink command because we use try_sudo \
+ (set :use_sudo, true) for several common deploy-related tasks, but symlinks \
+ are not part of the tasks that truly require sudo privileges
+
+ DESC
+ task :create_symlink, :except => { :no_release => true } do
+ on_rollback do
+ if previous_release
+ run "#{try_sudo} 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 "#{try_sudo} rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
+ end
+
+ desc <<-DESC
Clean up old releases. By default, the last 5 releases are kept on each \
server (though you can change this with the keep_releases variable). All \
other deployed revisions are removed from the servers. By default, this \
@@ -164,7 +200,7 @@
# adding a chown -R method to fix permissions on the directory
# this should help with issues related to permission denied
# as in issues #28 and #30
- run "#{try_sudo} chown -R #{user}:#{user} #{dir}" if remote_dir_exists?(dir)
+ run "chown -R #{user}:#{user} #{dir}" if remote_dir_exists?(dir)
set_perms_dirs(dir)
set_perms_files(dir)
@@ -178,6 +214,26 @@
end
end
end
+
+ namespace :rollback do
+ desc <<-DESC
+ [internal] Points the current symlink at the previous revision.
+ This is called by the rollback sequence, and should rarely (if
+ ever) need to be called directly.
+
+ AAI OVERRIDES:
+ removes use of try_sudo with symlink command because we use try_sudo \
+ (set :use_sudo, true) for several common deploy-related tasks, but symlinks \
+ are not part of the tasks that truly require sudo privileges
+ DESC
+ task :revision, :except => { :no_release => true } do
+ if previous_release
+ run "#{try_sudo} rm #{current_path}; ln -s #{previous_release} #{current_path}"
+ else
+ abort "could not rollback the code because there is no prior release"
+ end
+ end
+ end
end
# --------------------------------------------
@@ -270,12 +326,12 @@
# NGINX tasks
# --------------------------------------------
namespace :nginx do
- %w(start stop restart status).each do |cmd|
+ %w(start stop restart reload status).each do |cmd|
desc "[internal] - #{cmd.upcase} nginx and php-fpm"
task cmd.to_sym, :roles => :web do
- nginx_cmd = fetch(:nginx_init_command, "/etc/init.d/nginx")
- phpfpm_cmd = fetch(:phpfpm_init_command, "/etc/init.d/php-fpm")
+ nginx_cmd = fetch(:nginx_init_command, "service nginx")
+ phpfpm_cmd = fetch(:phpfpm_init_command, "service php5-fpm")
run "#{try_sudo} #{nginx_cmd} #{cmd}"
run "#{try_sudo} #{phpfpm_cmd} #{cmd}"
@@ -400,9 +456,9 @@
desc "Perform a backup of web and database files"
task :default do
deploy.setup_backup
- db
- web
- cleanup
+ backup.db
+ backup.web
+ backup.cleanup
end
desc <<-DESC
@@ -458,22 +514,46 @@
end
desc "Perform a backup of database files"
- task :db, :roles => :db do
+ task :db, :roles => :web do
if previous_release
mysqldump = fetch(:mysqldump, "mysqldump")
dump_options = fetch(:dump_options, "--single-transaction --create-options --quick")
+ dbhost = fetch(:db_remote_host, 'localhost')
puts "Backing up the database now and putting dump file in the previous release directory"
# create the temporary copy for the release directory
# which we'll tarball in the backup:web task
run "mkdir -p #{tmp_backups_path}/#{release_name}"
- # define the filename (include the current_path so the dump file will be within the directory)
- filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_dump-#{Time.now.to_s.gsub(/ /, "_")}.sql.gz"
- # dump the database for the proper environment
- run "#{mysqldump} #{dump_options} -u #{dbuser} -p #{dbname} | gzip -c --best > #{filename}" do |ch, stream, out|
- ch.send_data "#{dbpass}\n" if out =~ /^Enter password:/
+ now = Time.now.to_s.gsub(/ /, "_")
+ # ignored db tables
+ ignore_tables = fetch(:ignore_tables, [])
+ if !ignore_tables.empty?
+ ignore_tables_str = ''
+ ignore_tables.each{ |t| ignore_tables_str << "--ignore-table='#{dbname}'.'" + t + "' " }
+
+ # define the filenames (include the current_path so the dump file will be within the directory)
+ data_filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_data_dump-#{now}.sql.gz"
+ structure_filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_structure_dump-#{now}.sql.gz"
+
+ # dump the database structure for the proper environment
+ run "#{mysqldump} --single-transaction --create-options --quick --triggers --routines --no-data -h #{dbhost} -u #{dbuser} -p #{dbname} | gzip -c --best > #{structure_filename}" do |ch, stream, out|
+ ch.send_data "#{dbpass}\n" if out =~ /^Enter password:/
+ end
+
+ # dump the database data for the proper environment
+ run "#{mysqldump} #{dump_options} -h #{dbhost} -u #{dbuser} -p #{dbname} #{ignore_tables_str} | gzip -c --best > #{data_filename}" do |ch, stream, out|
+ ch.send_data "#{dbpass}\n" if out =~ /^Enter password:/
+ end
+ else
+ # define the filename (include the current_path so the dump file will be within the directory)
+ filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_dump-#{now}.sql.gz"
+
+ # dump the database for the proper environment
+ run "#{mysqldump} #{dump_options} -h #{dbhost} -u #{dbuser} -p #{dbname} | gzip -c --best > #{filename}" do |ch, stream, out|
+ ch.send_data "#{dbpass}\n" if out =~ /^Enter password:/
+ end
end
else
logger.important "no previous release to backup to; backup of database skipped"
View
@@ -45,7 +45,7 @@ def remote_dir_exists?(dir_path)
# set the permissions for files recurisvely from the starting directory (dir_path)
def set_perms_files(dir_path, perm = 644)
begin
- run "find #{dir_path} -type f -print0 | xargs -0 #{try_sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
+ run "find #{dir_path} -type f -print0 | xargs -0 -L 500 #{try_sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
rescue Exception => e
logger.important "FAILED to set permissions of #{perm} on files within #{dir_path}!"
logger.important e.message
@@ -62,7 +62,7 @@ def set_perms_files(dir_path, perm = 644)
# set the permissions for directories recursively from the starting directory (dir_path)
def set_perms_dirs(dir_path, perm = 755)
begin
- run "find #{dir_path} -type d -print0 | xargs -0 #{try_sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
+ run "find #{dir_path} -type d -print0 | xargs -0 -L 500 #{try_sudo} chmod #{perm}" if remote_dir_exists?(dir_path)
rescue Exception => e
logger.important "FAILED to set permissions of #{perm} on directories within #{dir_path}!"
logger.important e.message
View
@@ -27,7 +27,7 @@
# to just using `sudo` due to the concatenation in the sudo method.
#
# This assumes that you have set up your SSH user to have passwordless sudo
- # setup for common commands (e.g., mv, cp, ln, mkdir, chown, chmod, rm, etc.)
+ # setup for common commands (e.g., chmod, rm, rsync, etc.)
#
# (see: https://github.com/capistrano/capistrano/blob/legacy-v2/lib/capistrano/configuration/actions/invocation.rb#L229-L237)
set :sudo_prompt, ''
@@ -62,8 +62,8 @@
after "deploy", "drupal:symlink"
after "drupal:symlink_config_file", "drupal:run_makefiles"
after "drupal:symlink","drupal:protect"
+ after "drupal:symlink", "compass"
after "drupal:symlink", "drupal:clearcache"
- before "drupal:clearcache", "compass"
after "deploy", "deploy:cleanup"
# --------------------------------------------
@@ -97,7 +97,7 @@
# remove shared directories
multisites.each_pair do |folder, url|
if folder != url
- try_sudo "mv #{latest_release}/sites/#{folder} #{latest_release}/sites/#{url}"
+ run "mv #{latest_release}/sites/#{folder} #{latest_release}/sites/#{url}"
end
try_sudo "rm -Rf #{latest_release}/sites/#{url}/files"
end
@@ -143,19 +143,50 @@
namespace :backup do
desc "Perform a backup of database files"
- task :db, :roles => :db do
+ task :db, :roles => :web do
if previous_release
puts "Backing up the database now and putting dump file in the previous release directory"
# create the temporary copy for the release directory
# which we'll tarball in the backup:web task
run "mkdir -p #{tmp_backups_path}/#{release_name}"
- multisites.each_pair do |folder, url|
- # define the filename (include the current_path so the dump file will be within the directory)
- filename = "#{tmp_backups_path}/#{release_name}/#{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}"
+ now = Time.now.to_s.gsub(/ /, "_")
+ # ignored db tables
+ ignore_tables = fetch(:ignore_tables, [])
+ structure_tables_key = fetch(:structure_tables_key, 'structure-tables')
+
+ if !ignore_tables.empty?
+ if ignore_tables.is_a?(String)
+ ignore_tables_str = ignore_tables
+ else
+ ignore_tables_str = ignore_tables.join(',')
+ end
+
+ # define the filenames (include the current_path so the dump file will be within the directory)
+ data_filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_data_dump-#{now}.sql.gz"
+ structure_filename = "#{tmp_backups_path}/#{release_name}/#{dbname}_structure_dump-#{now}.sql.gz"
+
+ if ignore_tables_str == 'common'
+ skip_tables_opt = "--skip-tables-key"
+ else
+ skip_tables_opt = "--skip-tables-list"
+ end
+
+ multisites.each_pair do |folder, url|
+ # dump the database structure for the proper environment (structure dump of common tables)
+ run "#{drush_bin} -l #{url} -r #{current_path} sql-dump --structure-tables-key=#{structure_tables_key} | gzip -c --best > #{structure_filename}"
+
+ # dump the database data for the proper environment
+ run "#{drush_bin} -l #{url} -r #{current_path} sql-dump #{skip_tabls_opt}=#{ignore_tables_str} | gzip -c --best > #{data_filename}"
+ end
+ else
+ multisites.each_pair do |folder, url|
+ # define the filename (include the current_path so the dump file will be within the directory)
+ filename = "#{tmp_backups_path}/#{release_name}/#{folder}_dump-#{now}.sql.gz"
+ # dump the database for the proper environment (skip standard tables)
+ run "#{drush_bin} -l #{url} -r #{current_path} sql-dump --skip-tables-key=common | gzip -c --best > #{filename}"
+ end
end
else
logger.important "no previous release to backup; backup of database skipped"
Oops, something went wrong.

0 comments on commit 1f45d2e

Please sign in to comment.