Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gerrit Riessen
committed
Jan 7, 2011
1 parent
e671d4d
commit 1c1c6b0
Showing
19 changed files
with
523 additions
and
58 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
load 'deploy' if respond_to?(:namespace) # cap2 differentiator | ||
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } | ||
|
||
load 'config/deploy' # remove this line to skip loading any of the default tasks |
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
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
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
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 renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
set :stages, %w(staging production prodbackup beta) | ||
set :default_stage, "staging" | ||
require 'capistrano/ext/multistage' | ||
|
||
require File.dirname(__FILE__) + '/../lib/deploy_helpers' | ||
class << self | ||
include DeployHelpers::Bindings | ||
include DeployHelpers::Utils | ||
end | ||
|
||
set :application, "website" | ||
set :deploy_to, "/var/app/#{application}" | ||
set :user, "deploy" | ||
set :local_rails_root, File.expand_path(File.join(File.dirname(__FILE__), "..")) | ||
|
||
set :scm, :git | ||
set :repository, "gitosis@dev.2monki.es:#{ENV['GITREPO'] || application}.git" | ||
set :branch, ENV["GITBRANCH"] || "master" | ||
set :git_shallow_clone, 3 | ||
set :git_enable_submodules, 1 ## note, this does not work for deep modules only toplevel | ||
|
||
set :rvm_ruby_version, "ruby-1.9.2-head" | ||
|
||
namespace :deploy do | ||
{ ### After hooks | ||
"migrate" => "restart", | ||
"symlink" => "setup_paths", | ||
"setup_paths" => [ "run_remote_scripts", "generate_remote_files"], | ||
}.each do |after_task, before_tasks| | ||
[before_tasks].flatten.each do |before_task| | ||
after "deploy:#{after_task}", "deploy:#{before_task}" | ||
end | ||
end | ||
|
||
{ ### Before hooks | ||
"symlink" => "setup_diff", | ||
"set_passenger_version" => "setup_nginx_passenger_module", | ||
"restart" => ["show_diffs", "update_superglue", | ||
"set_passenger_version", "bundle_install"], | ||
}.each do |before_task, after_tasks| | ||
[after_tasks].flatten.each do |after_task| | ||
before "deploy:#{before_task}", "deploy:#{after_task}" | ||
end | ||
end | ||
|
||
desc "update the superglue and make sure it's still holding things together" | ||
task :update_superglue do | ||
run "cd ~/superglue && git pull" | ||
end | ||
|
||
desc "install gems with bundle" | ||
task :bundle_install do | ||
run_with_rvm(rvm_ruby_version, current_path) { "bundle install" } | ||
end | ||
|
||
desc "Need to use rvm to call rake, i.e. migrate won't work otherwise." | ||
task :migrate, :roles => :db do | ||
run_with_rvm(rvm_ruby_version, current_path) do | ||
"RAILS_ENV=production rake db:migrate" | ||
end | ||
end | ||
|
||
desc "create various paths and replace symlinks" | ||
task :setup_paths do | ||
[ | ||
# system folder is only used for maintenance, therefore whip it's ass | ||
[ "public/system", "#{shared_path}/system/maintenance"], | ||
|
||
# various yaml configurations | ||
["config/apis.yml", | ||
"#{shared_path}/system/config/apis.yml-#{application}"], | ||
["config/database.yml", | ||
"#{shared_path}/system/config/database.yml-#{application}"], | ||
|
||
# redirect the log symlink for log | ||
["log", "#{shared_path}/#{application}/log"], | ||
].each do |dest, src| | ||
dest = "#{current_path}/#{dest}" | ||
run "rm -fr #{dest} && ln -snf #{src} #{dest}" | ||
end | ||
end | ||
|
||
desc "Generate files on the remote server" | ||
task :generate_remote_files do | ||
{ | ||
"nginx.conf" => "#{current_path}/config", | ||
"monitrc" => "#{current_path}/config", | ||
}.each do |configfile, remote_path| | ||
remote_path = "#{remote_path}/#{configfile}" | ||
local_path = "config/remote_files/#{configfile}.erb" | ||
local_file = File.join(local_rails_root, local_path) | ||
erb = ERB.new(File.open(local_file).read) | ||
perm_val = ("%o" % File.stat(local_file).mode)[3..-1] | ||
binding_method = "generate_binding_for_#{configfile.gsub(/[.]/,'_')}" | ||
|
||
roles[:app].each do |server_def| | ||
put(erb.result( self.send(binding_method, | ||
generate_default_opts(server_def,current_path))), | ||
remote_path, :only => { :host_ip => server_def.options[:host_ip] }) | ||
|
||
run("chmod #{perm_val} #{remote_path}", | ||
:only => {:host_ip => server_def.options[:host_ip]}) | ||
|
||
@diff[server_def.host]. | ||
merge!({ configfile => | ||
capture("diff -C 1 #{current_path}/#{local_path} " + | ||
"#{remote_path} || echo", | ||
:only => {:host_ip => server_def.options[:host_ip]})}) | ||
end | ||
end | ||
end | ||
|
||
desc "Do stuff on the server to which we have just deployed" | ||
task :run_remote_scripts do | ||
[ | ||
## TODO add some! | ||
].each do |basename| | ||
binding_method = "generate_binding_for_#{basename.gsub(/[.]/,'_')}" | ||
local_path = File.join(local_rails_root, "config", "remote_scripts", | ||
"#{basename}.erb") | ||
remote_path = "#{current_path}/tmp/#{basename}" | ||
erb = ERB.new(File.open(local_path).read) | ||
|
||
roles[:app].each do |server_def| | ||
put(erb.result(self.send(binding_method, | ||
generate_default_opts(server_def,current_path))), | ||
remote_path, :only => { :host_ip => server_def.options[:host_ip] }) | ||
run("ruby #{remote_path}", :only => {:host_ip => server_def.options[:host_ip]}) | ||
end | ||
end | ||
end | ||
|
||
# Restart passenger on deploy | ||
desc "Restarting passenger with restart.txt" | ||
task :restart, :roles => :app, :except => { :no_release => true } do | ||
run "touch #{current_path}/tmp/restart.txt" | ||
end | ||
|
||
# show all the diffs we did. this makes the deploy a little more understandable if | ||
# we have the differs at the end and all the "deploy stuff". | ||
task :show_diffs do | ||
puts " All went well, just about to restart but first the differs" | ||
puts " --8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<--8<" | ||
(@diff||{}).each do |server, diffs| | ||
puts " ## Server: #{server}" | ||
diffs.each do |filename, diffstr| | ||
puts " @@@@@@@@@@@@@@@@@@@ File: #{filename} @ #{server}" | ||
puts diffstr | ||
end | ||
end | ||
puts " -->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8-->8" | ||
end | ||
task(:setup_diff) { @diff = Hash.new { |h,k| h[k] = Hash.new } } | ||
|
||
[:start, :stop].each do |t| | ||
desc "#{t} task is a no-op with mod_rails" | ||
task t, :roles => :app do ; end | ||
end | ||
end |
Oops, something went wrong.