Skip to content

Commit

Permalink
Added support for :except on task declarations as the opposite of :on…
Browse files Browse the repository at this point in the history
…ly [DHH] Changed setup, update_code, rollback_code, and symlink to work on all servers instead of only those in the :app, :web, and :db roles. A server can opt out of being part of the release deployment by setting :no_release => true [DHH]

git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@4041 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 26, 2006
1 parent 05f7d60 commit bcac17e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG
@@ -1,9 +1,24 @@
*SVN*

* Changed setup, update_code, rollback_code, and symlink to work on all servers instead of only those in the :app, :web, and :db roles. A server can opt out of being part of the release deployment by setting :no_release => true [DHH]

* Added support for :except on task declarations as the opposite of :only [DHH]. Example:

role :app, "192.168.0.2"
role :file, "192.168.0.3", :no_release => true

task :symlink, :except => { :no_release => true } do
on_rollback { run "ln -nfs #{previous_release} #{current_path}" }
run "ln -nfs #{current_release} #{current_path}"
end

cap symlink # will not run on 192.168.0.3

* Deprecate the -r/--recipe switch in favor of -f/--file (for more make/rake-like semantics) [Jamis Buck]

* Fix gemspec to include a dependency on rake 0.7 [Jamis Buck]

>>>>>>> .r4040
* Added respect for ENV["HOSTS"] that'll be used instead of the roles specified in the task definition [DHH]. Example:

HOSTS=192.168.0.1 cap setup # one-off setup for that server, doesn't need to be prespecified in the recipes file
Expand Down
40 changes: 28 additions & 12 deletions lib/capistrano/actor.rb
Expand Up @@ -85,18 +85,8 @@ def servers
@servers = hosts
else
roles = find_roles
only = @options[:only] || {}

unless only.empty?
roles = roles.delete_if do |role|
catch(:done) do
only.keys.each do |key|
throw(:done, true) if role.options[key] != only[key]
end
false
end
end
end
apply_only!(roles)
apply_except!(roles)

@servers = roles.map { |role| role.host }.uniq
end
Expand All @@ -122,6 +112,32 @@ def environment_values(key, use_symbols = false)
use_symbols ? values.collect { |e| e.to_sym } : values
end
end

def apply_only!(roles)
only = @options[:only] || {}

unless only.empty?
roles = roles.delete_if do |role|
catch(:done) do
only.keys.each { |key| throw(:done, true) if role.options[key] != only[key] }
false
end
end
end
end

def apply_except!(roles)
except = @options[:except] || {}

unless except.empty?
roles = roles.delete_if do |role|
catch(:done) do
except.keys.each { |key| throw(:done, true) if role.options[key] == except[key] }
false
end
end
end
end
end

def initialize(config) #:nodoc:
Expand Down
10 changes: 5 additions & 5 deletions lib/capistrano/recipes/standard.rb
Expand Up @@ -35,7 +35,7 @@
end

desc "Set up the expected application directory structure on all boxes"
task :setup, :roles => [:app, :db, :web] do
task :setup, :except => { :no_release => true } do
run <<-CMD
mkdir -p -m 775 #{releases_path} #{shared_path}/system &&
mkdir -p -m 777 #{shared_path}/log
Expand Down Expand Up @@ -64,7 +64,7 @@
Update all servers with the latest release of the source code. All this does
is do a checkout (as defined by the selected scm module).
DESC
task :update_code, :roles => [:app, :db, :web] do
task :update_code, :except => { :no_release => true } do
on_rollback { delete release_path, :recursive => true }

source.checkout(self)
Expand All @@ -80,7 +80,7 @@
Rollback the latest checked-out version to the previous one by fixing the
symlinks and deleting the current release from all servers.
DESC
task :rollback_code, :roles => [:app, :db, :web] do
task :rollback_code, :except => { :no_release => true } do
if releases.length < 2
raise "could not rollback the code because there is no prior release"
else
Expand All @@ -95,7 +95,7 @@
Update the 'current' symlink to point to the latest version of
the application's code.
DESC
task :symlink, :roles => [:app, :db, :web] do
task :symlink, :except => { :no_release => true } do
on_rollback { run "ln -nfs #{previous_release} #{current_path}" }
run "ln -nfs #{current_release} #{current_path}"
end
Expand Down Expand Up @@ -239,4 +239,4 @@
task :invoke, :roles => Capistrano.str2roles(ENV["ROLES"] || "") do
method = ENV["SUDO"] ? :sudo : :run
send(method, ENV["COMMAND"])
end
end
9 changes: 9 additions & 0 deletions test/actor_test.rb
Expand Up @@ -230,6 +230,15 @@ def test_run_in_task_with_only_restricts_selected_roles
assert_equal %w(01.example.com), @actor.sessions.keys.sort
end

def test_run_in_task_with_except_restricts_selected_roles
@actor.define_task :foo, :roles => :db, :except => { :primary => true } do
run "do this"
end

@actor.foo
assert_equal %w(02.example.com all.example.com), @actor.sessions.keys.sort
end

def test_run_in_task_with_single_host_selected
@actor.define_task :foo, :hosts => "01.example.com" do
run "do this"
Expand Down

0 comments on commit bcac17e

Please sign in to comment.