1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

[switchtower] Look for config/deploy.rb and stasks file by default. Make the generated switchtower.rake file use rake namespaces, and include all default tasks.

git-svn-id: http://svn.rubyonrails.org/rails/tools/switchtower@3688 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jamis Buck 2006-02-27 15:55:18 +00:00
parent b10c6be87f
commit 6805acca6d
6 changed files with 79 additions and 34 deletions

View file

@ -1,3 +1,10 @@
*1.0.2* *SVN*
* Make the generated switchtower.rake file use rake namespaces, and include all default tasks
* Look for config/deploy.rb and stasks file by default
*1.0.1* (February 20th, 2006)
* Fix broken switchtower_invoke function in switchtower.rake (missing require statement)

View file

@ -131,6 +131,33 @@ module SwitchTower
end
end
# Iterates over each task, in alphabetical order. A hash object is
# yielded for each task, which includes the task's name (:name), the
# length of the longest task name (:longest), and the task's description,
# reformatted as a single line (:desc).
def each_task
keys = tasks.keys.sort_by { |a| a.to_s }
longest = keys.inject(0) { |len,key| key.to_s.length > len ? key.to_s.length : len } + 2
keys.sort_by { |a| a.to_s }.each do |key|
desc = (tasks[key].options[:desc] || "").gsub(/(?:\r?\n)+[ \t]*/, " ").strip
info = { :task => key, :longest => longest, :desc => desc }
yield info
end
end
# Dump all tasks and (brief) descriptions in YAML format for consumption
# by other processes. Returns a string containing the YAML-formatted data.
def dump_tasks
data = ""
each_task do |info|
desc = info[:desc].split(/\. /).first || ""
desc << "." if !desc.empty? && desc[-1] != ?.
data << "#{info[:task]}: #{desc}\n"
end
data
end
# Execute the given command on all servers that are the target of the
# current task. If a block is given, it is invoked for all output
# generated by the command, and should accept three parameters: the SSH

View file

@ -165,6 +165,10 @@ module SwitchTower
"Default: don't pretend.)"
) { |value| @options[:pretend] = value }
opts.on("-q", "--quiet",
"Make the output as quiet as possible (the default)"
) { @options[:verbose] = 0 }
opts.on("-v", "--verbose",
"Specify the verbosity of the output.",
"May be given multiple times. (Default: silent)"
@ -250,6 +254,7 @@ DETAIL
APPLY_TO_OPTIONS = [:apply_to]
RECIPE_OPTIONS = [:password]
DEFAULT_RECIPES = %w(stasks config/deploy.rb)
# A sanity check to ensure that a valid operation is specified.
def check_options!
@ -261,6 +266,7 @@ DETAIL
if apply_to_given && recipe_given
abort "You cannot specify both recipe options and framework integration options."
elsif !apply_to_given
look_for_default_recipe_file! if @options[:recipes].empty?
abort "You must specify at least one recipe" if @options[:recipes].empty?
abort "You must specify at least one action" if @options[:actions].empty?
else
@ -268,5 +274,14 @@ DETAIL
@options[:recipe_file] = args.shift
end
end
def look_for_default_recipe_file!
DEFAULT_RECIPES.each do |file|
if File.exist?(file)
@options[:recipes] << file
break
end
end
end
end
end

View file

@ -15,39 +15,37 @@ def switchtower_invoke(*actions)
options = actions.last.is_a?(Hash) ? actions.pop : {}
args = %w[-r config/deploy]
verbose = options[:verbose] || "-vvvvv"
verbose = options[:verbose] || "-vvv"
args << verbose
args.concat(actions.map { |act| ["-a", act.to_s] }.flatten)
SwitchTower::CLI.new(args).execute!
end
desc "Push the latest revision into production"
task :deploy do
switchtower_invoke :deploy
end
namespace :remote do
<%- config = SwitchTower::Configuration.new
config.load "standard"
options = { :show_tasks => ", :verbose => ''" }
config.actor.each_task do |info| -%>
<%- unless info[:desc].empty? -%>
desc "<%= info[:desc].scan(/.*?(?:\. |$)/).first.strip.gsub(/"/, "\\\"") %>"
<%- end -%>
task(<%= info[:task].inspect %>) { switchtower_invoke <%= info[:task].inspect %><%= options[info[:task]] %> }
desc "Rollback to the release before the current release in production"
task :rollback do
switchtower_invoke :rollback
end
<%- end -%>
desc "Execute a specific action using switchtower"
task :exec do
unless ENV['ACTION']
raise "Please specify an action (or comma separated list of actions) via the ACTION environment variable"
end
desc "Describe the differences between HEAD and the last production release"
task :diff_from_last_deploy do
switchtower_invoke :diff_from_last_deploy
end
desc "Enumerate all available deployment tasks"
task :show_deploy_tasks do
switchtower_invoke :show_tasks, :verbose => ""
end
desc "Execute a specific action using switchtower"
task :remote_exec do
unless ENV['ACTION']
raise "Please specify an action (or comma separated list of actions) via the ACTION environment variable"
actions = ENV['ACTION'].split(",")
switchtower_invoke(*actions)
end
actions = ENV['ACTION'].split(",")
switchtower_invoke(*actions)
end
desc "Push the latest revision into production (delegates to remote:deploy)"
task :deploy => "remote:deploy"
desc "Rollback to the release before the current release in production (delegates to remote:rollback)"
task :rollback => "remote:rollback"

View file

@ -23,15 +23,13 @@ set :spinner_user, :app
desc "Enumerate and describe every available task."
task :show_tasks do
keys = tasks.keys.sort_by { |a| a.to_s }
longest = keys.inject(0) { |len,key| key.to_s.length > len ? key.to_s.length : len } + 2
puts "Available tasks"
puts "---------------"
tasks.keys.sort_by { |a| a.to_s }.each do |key|
desc = (tasks[key].options[:desc] || "").strip.split(/\r?\n/)
puts "%-#{longest}s %s" % [key, desc.shift]
puts "%#{longest}s %s" % ["", desc.shift] until desc.empty?
each_task do |info|
wrap_length = 80 - info[:longest]
lines = info[:desc].gsub(/(.{1,#{wrap_length}})(?:\s|\Z)+/, "\\1\n").split(/\n/)
puts "%-#{info[:longest]}s %s" % [info[:task], lines.shift]
puts "%#{info[:longest]}s %s" % ["", lines.shift] until lines.empty?
puts
end
end

View file

@ -20,7 +20,7 @@ module SwitchTower
MAJOR = 1
MINOR = 0
TINY = 1
TINY = 2
STRING = [MAJOR, MINOR, TINY].join(".")