Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 9a3e16f459
Fetching contributors…

Cannot retrieve contributors at this time

174 lines (145 sloc) 6.388 kB
# Capistrano 1 and 2 have different configuration locations
configuration = Capistrano::Configuration.respond_to?(:instance) ?
Capistrano::Configuration.instance(:must_exist) :
Capistrano.configuration(:must_exist)
configuration.load do
set :scm, :git
set :deploy_via, :remote_cache
set :shared_dir, "."
set :repository_cache, "current"
set :scm_verbose, true
set :use_sudo, false
def strip_cygdrive(path)
path.sub /\/cygdrive\/([c-z])\//, '\1:/'
end
def latest_release
strip_cygdrive current_path
end
# We can't run ruby commands directly, because the rake script searches for ruby based on windows paths that aren't valid in this environment
def ruby_cmd(gem, cmd=gem)
"PATH=\"#{File.dirname ruby_exe_path}:$PATH\" #{ruby_exe_path} -e \"require 'rubygems'; gem '#{gem}', '>= 0'; load Gem.bin_path('#{gem}', '#{cmd}', '>= 0')\""
end
def rubygems_cmd
"PATH=\"#{File.dirname ruby_exe_path}:$PATH\" #{ruby_exe_path} -e \"require 'rubygems';require 'rubygems/gem_runner';require 'rubygems/exceptions';Gem::GemRunner.new.run ARGV.clone\""
end
def application_server
app_server rescue :mongrel
end
namespace :deploy do
desc "Update the code on the server by doing a git reset --hard <ref> in the current/ directory"
task :update_code do
# update_repository_cache will attempt to clean out the repository; we must prevent that.
# /bin/git below is where www.windowsgit.com's windows git/ssh installation puts the git executable.
# This creates a git proxy that goes in $PATH before /bin, which will filter out any `git clean` commands.
run "mkdir -p '#{shared_path}/bin'"
run <<-RUN
echo 'if [ "$1" != "clean" ]; then /bin/git $*; fi' > "#{shared_path}/bin/git.exe"
RUN
alter_path_cmd = "export PATH=#{shared_path}/bin:$PATH # Required for capistrano-windows-server"
run <<-RUN
if ! grep '#{alter_path_cmd}' ~/.bashrc > /dev/null; then echo '#{alter_path_cmd}' >> ~/.bashrc; fi
RUN
strategy.send 'update_repository_cache'
finalize_update
end
desc <<-DESC
Prepares one or more servers for deployment. Before you can use any \
of the Capistrano deployment tasks with your project, you will need to \
make sure all of your servers have been prepared with `cap deploy:setup'. When \
you add a new server to your cluster, you can easily run the setup task \
on just that server by specifying the HOSTS environment variable:
$ cap HOSTS=new.server.com deploy:setup
It is safe to run this task on servers that have already been set up; it \
will not destroy any deployed revisions or data.
DESC
task :setup do
dirs = [deploy_to]
run "mkdir -p #{dirs.join(' ')} && chmod g+w #{dirs.join(' ')}"
if exists?(:repository_host_key)
run "if ! grep '#{repository_host_key}' ~/.ssh/known_hosts > /dev/null; then echo '#{repository_host_key}' >> ~/.ssh/known_hosts; fi"
end
end
# Clear out tasks that are not appropriate on Windows
%w(finalize_update symlink cleanup).each do |removed_task|
task removed_task do; end
end
namespace :rollback do
%w(code default).each do |removed_task|
task removed_task do; end
end
end
desc "Run pending migrations"
task :migrate do
run "cd #{current_path} && #{ruby_cmd 'rake'} db:migrate RAILS_ENV=#{rails_env}"
end
desc "Start mongrel"
task :start do
return unless application_server == :mongrel
mongrel_instances.each do |n|
run "net start #{mongrel_instance_prefix}#{n}; true"
end
end
desc "Stop mongrel"
task :stop do
return unless application_server == :mongrel
mongrel_instances.each do |n|
run "net stop #{mongrel_instance_prefix}#{n}; true"
end
end
desc "Restart mongrel"
task :restart do
return unless application_server == :mongrel
mongrel_instances.each do |n|
run "net stop #{mongrel_instance_prefix}#{n}; true"
run "net start #{mongrel_instance_prefix}#{n}; true"
end
end
namespace :mongrel do
desc "Create mongrel services"
task :setup do
return unless application_server == :mongrel
mongrel_instances.each do |n|
run "mkdir -p #{current_path}/{tmp,log}" # These are often not under version control, but their absence keeps mongrel from recognizing the rails app
run "cd #{current_path} && #{ruby_cmd 'mongrel', 'mongrel_rails'} service::install -e #{rails_env} -N #{mongrel_instance_prefix}#{n} -p #{base_port + n - mongrel_instances.first}; true"
run %Q(sc.exe config "#{mongrel_instance_prefix}#{n}" start= auto type= interact type= own; true)
end
end
desc "Remove mongrel services"
task :remove do
mongrel_instances.each do |n|
run "#{ruby_cmd 'mongrel', 'mongrel_rails'} service::remove -N #{mongrel_instance_prefix}#{n}; true"
end
end
end
end
desc "Run a rake command in COMMAND"
task :rake do
raise "Specify the command with COMMAND='some:task with_arguments'" unless ENV['COMMAND']
run "cd #{current_path} && #{ruby_cmd 'rake'} #{ENV['COMMAND']} RAILS_ENV=#{rails_env}"
end
desc "Run a rubygems (gem) command in COMMAND"
task :rubygems do
raise "Specify the command with COMMAND='install rails'" unless ENV['COMMAND']
run "cd #{current_path} && #{rubygems_cmd} #{ENV['COMMAND']}"
end
namespace :git do
desc "Run a git command in COMMAND"
task :execute do
raise "Specify the command with COMMAND. eg: COMMAND='diff HEAD^^'" unless ENV['COMMAND']
run "cd #{current_path} && git #{ENV['COMMAND']}"
end
end
namespace :bundle do
desc "Install gems with bundler"
task :install do
run "cd #{current_path} && #{ruby_cmd 'bundler', 'bundle'} install --without test development --path #{strip_cygdrive deploy_to}/bundle"
end
desc "Execute a COMMAND with bundle exec"
task :execute do
raise "Specify the command with COMMAND. eg: COMMAND='rake db:migrate'" unless ENV['COMMAND']
run "cd #{current_path} && #{ruby_cmd 'bundler', 'bundle'} exec #{ENV['COMMAND']}"
end
end
after 'deploy:setup', 'deploy:update_code'
after 'deploy:setup', 'deploy:mongrel:setup'
end
Jump to Line
Something went wrong with that request. Please try again.