Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Switched to using bundler capistrano tasks. Moved custom task definit…
Browse files Browse the repository at this point in the history
…ions into lib/deploy/. Removed hoptoad-related load path munging as that gem is now in Gemfile.
  • Loading branch information
Tom Copeland committed Feb 7, 2011
1 parent 0833ae7 commit 00b0fb6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 78 deletions.
1 change: 1 addition & 0 deletions Capfile
@@ -1,3 +1,4 @@
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
Dir['lib/deploy/*.rb'].each { |r| load(r) }
load 'config/deploy'
82 changes: 4 additions & 78 deletions config/deploy.rb
Expand Up @@ -2,102 +2,28 @@
set :default_stage, "staging"

require 'capistrano/ext/multistage'
require 'bundler/capistrano'

default_run_options[:pty] = true

set :ssh_options, { :forward_agent => true }

set :application, "gemcutter"
set(:rails_env) { "#{stage}"}

# Note that this requires you run 'ssh-add' on your workstation in order to
# add your private key to the ssh agent. If that's not good for you, just uncomment the
# "set :deploy_via, :copy" and comment "set :deploy_via, :remote_cache"
set :scm, :git
set :repository, "git://github.com/rubygems/gemcutter"
set :repository, "git://github.com/rubygems/#{application}"
set :repository_cache, "git_cache"
set :git_enable_submodules, 1
set :deploy_via, :remote_cache
set :git_shallow_clone, 1
set :use_sudo, false

set :group, "rubycentral"
set :user, "rubycentral"

set :ree_path, "/opt/ruby-enterprise-1.8.7-2010.02/bin"

namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end

[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end

desc "Move in database.yml for this environment"
task :move_in_database_yml, :roles => :app do
run "cp #{deploy_to}/shared/config/database.yml #{current_path}/config/"
end

desc "Run gem bundle"
task :bundle, :roles => :app do
env = "PATH=/usr/local/pgsql/bin:/usr/local/bin:/bin:/usr/bin RAILS_ENV=#{rails_env} #{ree_path}"
run "#{env}/bundle install --gemfile #{release_path}/Gemfile --path #{fetch(:bundle_dir, "#{shared_path}/bundle")} --deployment --without development test"
end

desc "Migrate with bundler"
task :migrate_with_bundler, :roles => :app do
run "cd #{release_path} && #{ree_path}/rake db:migrate RAILS_ENV=#{rails_env}"
end

desc "Move in secret settings for this environment"
task :move_in_secret_settings, :roles => :app do
run "cp #{deploy_to}/shared/config/secret.rb #{current_path}/config/secret.rb"
run "cp #{deploy_to}/shared/config/newrelic.yml #{current_path}/config/newrelic.yml"
end
end

namespace :maintenance do
desc "Go to maintenance mode"
task :on, :roles => :app do
run "touch #{current_path}/tmp/maintenance_mode"
deploy.restart
end
desc "Back to normal non-maintenance mode"
task :off, :roles => :app do
run "rm -f #{current_path}/tmp/maintenance_mode"
deploy.restart
end
end

namespace :bluepill do
desc "Stop processes that bluepill is monitoring and quit bluepill"
task :quit, :roles => [:app] do
sudo "bluepill stop; true"
sudo "bluepill quit; true"
end

desc "Load bluepill configuration and start it"
task :start, :roles => [:app] do
sudo "bluepill load #{release_path}/config/pills/#{rails_env}.rb"
end

desc "Prints bluepills monitored processes statuses"
task :status, :roles => [:app] do
sudo "bluepill status"
end
end

after "deploy", "deploy:migrate"
after "deploy:update", "bluepill:quit", "bluepill:start"

after "deploy:update_code", "deploy:bundle"
after "deploy", "deploy:migrate_with_bundler"
after "deploy", "deploy:cleanup"
after "deploy:symlink", "deploy:move_in_database_yml", "deploy:move_in_secret_settings"

Dir[File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'hoptoad_notifier-*')].each do |vendored_notifier|
$: << File.join(vendored_notifier, 'lib')
end
before "bundle:install", "deploy:set_config_for_pg_gem"
18 changes: 18 additions & 0 deletions lib/deploy/bluepill.rb
@@ -0,0 +1,18 @@
namespace :bluepill do
desc "Stop processes that bluepill is monitoring and quit bluepill"
task :quit, :roles => [:app] do
sudo "bluepill stop; true"
sudo "bluepill quit; true"
end

desc "Load bluepill configuration and start it"
task :start, :roles => [:app] do
sudo "bluepill load #{release_path}/config/pills/#{rails_env}.rb"
end

desc "Prints bluepills monitored processes statuses"
task :status, :roles => [:app] do
sudo "bluepill status"
end
end

31 changes: 31 additions & 0 deletions lib/deploy/misc.rb
@@ -0,0 +1,31 @@
namespace :deploy do
desc "Move in database.yml for this environment"
task :move_in_database_yml, :roles => :app do
run "cp #{deploy_to}/shared/config/database.yml #{current_path}/config/"
end

desc "Move in secret settings for this environment"
task :move_in_secret_settings, :roles => :app do
run "cp #{deploy_to}/shared/config/secret.rb #{current_path}/config/secret.rb"
run "cp #{deploy_to}/shared/config/newrelic.yml #{current_path}/config/newrelic.yml"
end

task :set_config_for_pg_gem, :roles => [:app, :db] do
run "cd #{current_path} && bundle config build.pg --with-pg-config=/usr/local/pgsql/bin/pg_config --no-rdoc --no-ri"
end

end

namespace :maintenance do
desc "Go to maintenance mode"
task :on, :roles => :app do
run "touch #{current_path}/tmp/maintenance_mode"
deploy.restart
end
desc "Back to normal non-maintenance mode"
task :off, :roles => :app do
run "rm -f #{current_path}/tmp/maintenance_mode"
deploy.restart
end
end

11 changes: 11 additions & 0 deletions lib/deploy/passenger.rb
@@ -0,0 +1,11 @@
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end

[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
end

0 comments on commit 00b0fb6

Please sign in to comment.