Created
August 13, 2013 09:40
-
-
Save donovan-duplessis/6219508 to your computer and use it in GitHub Desktop.
This file contains 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
# File: deploy.rb | |
# Author: Donovan du Plessis | |
# Description: Capistrano Deployment Automation | |
# Last Modified: May 17, 2012 | |
default_run_options[:pty] = true | |
set :application, "pwnurl" | |
set :repository, "git@github.com:SDC2012/intranet.git" | |
set :use_sudo, false | |
ssh_options[:forward_agent] = true | |
ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa")] | |
set :scm, :git | |
set :user, "donovan" | |
set :password, "dono$$va" | |
set :deploy_via, :remote_cache | |
set :copy_exclude, [".git", ".gitignore"] | |
set :copy_compression, :gzip | |
set :domain, "#{application}.com" | |
set :branch, "master" | |
set :deploy_to, "/control/apps/#{application}" | |
set :keep_releases, 2 | |
valid_deploys = { | |
'mis.hireresolve.co.za' => 'hireresolve', | |
'mis.hireresolve.com' => 'hireresolve', | |
'mis.staffingprojects.co.za' => 'staffingprojects', | |
'mis.tumaini.co.za' => 'tumaini', | |
'mis.goldmantech.co.za' => 'goldmantech', | |
'mis.goldmantechjobs.com' => 'goldmantech' | |
} | |
# Environment setup | |
unless ENV['deploy'].nil? | |
desc "Setup site-specific configuration parameters" | |
domain = ENV['deploy'] | |
if not valid_deploys.has_key?(domain) | |
puts "Invalid deploy domain specified: #{domain}" | |
exit 1 | |
end | |
deploy = valid_deploys[domain] | |
set :application, deploy.capitalize + ' Intranet' | |
set :domain, domain | |
set :deploy_to, "/control/apps/#{deploy}" | |
puts "*** Deploying the \033[1;41m #{application} \033[0m to server #{domain}" | |
else | |
puts "*** Deploying the \033[1;42m #{application} \033[0m to server #{domain}" | |
end | |
role :app, domain | |
role :web, domain | |
role :db, domain, :primary => true | |
namespace :deploy do | |
task :restart, :roles => :app do | |
framework_setup | |
end | |
namespace :web do | |
desc "Lock the current access during deployment" | |
task :disable, :roles => :app do | |
run "touch #{current_release}/app/webroot/.capistrano-lock" | |
end | |
desc "Unlock the current access after deployment" | |
task :enable, :roles => :app do | |
run "rm #{current_release}/app/webroot/.capistrano-lock" | |
end | |
end | |
desc "Setup cakephp framework to ensure clean restart" | |
task :framework_setup, :roles => :app do | |
# Set <basedir>/app/tmp directory (+ sub directories) permissions to a+rwx | |
sudo_run "chmod -R 777 #{current_path}/app/tmp" | |
# Move <basedir>/app/config/database.<app>.php to database.php | |
#run <<-CMD | |
# mv #{current_path}/app/config/database.#{domain}.php \ | |
# #{current_path}/app/config/database.php | |
#CMD | |
# Set debug value to 0 in <basedir>/app/config/core.php | |
run <<-CMD | |
perl -pi -e "s/debug', [0-9]{1}/debug', 0/gi" \ | |
#{current_path}/app/config/core.php | |
CMD | |
# Remove all cached models in <basedir>/app/tmp/cache/models/ | |
run "rm -rf #{current_path}/app/tmp/cache/models/*" | |
end | |
end | |
# Run specified task through remote /etc/init.d/apache2 command | |
namespace :apache do | |
[:stop, :start, :restart, :reload].each do |action| | |
desc "#{action.to_s.capitalize} Apache" | |
task action, :roles => :web do | |
sudo_run "/etc/init.d/apache2 #{action.to_s}" | |
end | |
end | |
end | |
# Run a command on the remote server with sudo and enter required password | |
def sudo_run(command) | |
run("sudo #{command}") do |channel, stream, output| | |
channel.send_data("#{password}\n") if output | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment