HeSYINUvSBZfxqA-capistrano 2.5.21
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/CHANGELOG +866 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +31 -0
- data/HeSYINUvSBZfxqA-capistrano.gemspec +49 -0
- data/README.mdown +65 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/bin/cap +4 -0
- data/bin/capify +86 -0
- data/lib/capistrano.rb +2 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/cli/execute.rb +85 -0
- data/lib/capistrano/cli/help.rb +125 -0
- data/lib/capistrano/cli/help.txt +78 -0
- data/lib/capistrano/cli/options.rb +243 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/command.rb +286 -0
- data/lib/capistrano/configuration.rb +44 -0
- data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
- data/lib/capistrano/configuration/actions/inspect.rb +46 -0
- data/lib/capistrano/configuration/actions/invocation.rb +295 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +204 -0
- data/lib/capistrano/configuration/execution.rb +143 -0
- data/lib/capistrano/configuration/loading.rb +197 -0
- data/lib/capistrano/configuration/namespaces.rb +197 -0
- data/lib/capistrano/configuration/roles.rb +73 -0
- data/lib/capistrano/configuration/servers.rb +98 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/errors.rb +19 -0
- data/lib/capistrano/extensions.rb +57 -0
- data/lib/capistrano/logger.rb +59 -0
- data/lib/capistrano/processable.rb +53 -0
- data/lib/capistrano/recipes/compat.rb +32 -0
- data/lib/capistrano/recipes/deploy.rb +597 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +111 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +274 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
- data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +138 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +88 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +223 -0
- data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +56 -0
- data/lib/capistrano/shell.rb +260 -0
- data/lib/capistrano/ssh.rb +101 -0
- data/lib/capistrano/task_definition.rb +75 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/rvmrc.sample +1 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +329 -0
- data/test/cli/ui_test.rb +28 -0
- data/test/cli_test.rb +17 -0
- data/test/command_test.rb +286 -0
- data/test/configuration/actions/file_transfer_test.rb +61 -0
- data/test/configuration/actions/inspect_test.rb +65 -0
- data/test/configuration/actions/invocation_test.rb +225 -0
- data/test/configuration/callbacks_test.rb +220 -0
- data/test/configuration/connections_test.rb +349 -0
- data/test/configuration/execution_test.rb +175 -0
- data/test/configuration/loading_test.rb +132 -0
- data/test/configuration/namespace_dsl_test.rb +311 -0
- data/test/configuration/roles_test.rb +144 -0
- data/test/configuration/servers_test.rb +158 -0
- data/test/configuration/variables_test.rb +190 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +135 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/bzr_test.rb +51 -0
- data/test/deploy/scm/darcs_test.rb +37 -0
- data/test/deploy/scm/git_test.rb +184 -0
- data/test/deploy/scm/mercurial_test.rb +134 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/scm/subversion_test.rb +32 -0
- data/test/deploy/strategy/copy_test.rb +302 -0
- data/test/extensions_test.rb +69 -0
- data/test/fixtures/cli_integration.rb +5 -0
- data/test/fixtures/config.rb +5 -0
- data/test/fixtures/custom.rb +3 -0
- data/test/logger_test.rb +123 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +121 -0
- data/test/shell_test.rb +90 -0
- data/test/ssh_test.rb +113 -0
- data/test/task_definition_test.rb +116 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +39 -0
- metadata +271 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
HeSYINUvSBZfxqA-capistrano (2.5.21)
|
5
|
+
highline
|
6
|
+
net-scp (>= 1.0.0)
|
7
|
+
net-sftp (>= 2.0.0)
|
8
|
+
net-ssh (>= 2.0.14)
|
9
|
+
net-ssh-gateway (>= 1.0.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: http://rubygems.org/
|
13
|
+
specs:
|
14
|
+
highline (1.6.2)
|
15
|
+
metaclass (0.0.1)
|
16
|
+
mocha (0.10.0)
|
17
|
+
metaclass (~> 0.0.1)
|
18
|
+
net-scp (1.0.4)
|
19
|
+
net-ssh (>= 1.99.1)
|
20
|
+
net-sftp (2.0.5)
|
21
|
+
net-ssh (>= 2.0.9)
|
22
|
+
net-ssh (2.2.1)
|
23
|
+
net-ssh-gateway (1.1.0)
|
24
|
+
net-ssh (>= 1.99.1)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
HeSYINUvSBZfxqA-capistrano!
|
31
|
+
mocha
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "capistrano/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "HeSYINUvSBZfxqA-capistrano"
|
7
|
+
s.version = Capistrano::Version.to_s
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jamis Buck", "Lee Hambley"]
|
10
|
+
s.email = ["jamis@jamisbuck.org", "lee.hambley@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/capistrano/capistrano"
|
12
|
+
s.summary = %q{Capistrano - Welcome to easy deployment with Ruby over SSH}
|
13
|
+
s.description = %q{Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH.}
|
14
|
+
s.date = %q{2011-03-22}
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.extra_rdoc_files = [
|
21
|
+
"README.mdown"
|
22
|
+
]
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
s.specification_version = 3
|
26
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<highline>, [">= 0"])
|
28
|
+
s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.14"])
|
29
|
+
s.add_runtime_dependency(%q<net-sftp>, [">= 2.0.0"])
|
30
|
+
s.add_runtime_dependency(%q<net-scp>, [">= 1.0.0"])
|
31
|
+
s.add_runtime_dependency(%q<net-ssh-gateway>, [">= 1.0.0"])
|
32
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
33
|
+
else
|
34
|
+
s.add_dependency(%q<net-ssh>, [">= 2.0.14"])
|
35
|
+
s.add_dependency(%q<net-sftp>, [">= 2.0.0"])
|
36
|
+
s.add_dependency(%q<net-scp>, [">= 1.0.0"])
|
37
|
+
s.add_dependency(%q<net-ssh-gateway>, [">= 1.0.0"])
|
38
|
+
s.add_dependency(%q<highline>, [">= 0"])
|
39
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
40
|
+
end
|
41
|
+
else
|
42
|
+
s.add_dependency(%q<net-ssh>, [">= 2.0.14"])
|
43
|
+
s.add_dependency(%q<net-sftp>, [">= 2.0.0"])
|
44
|
+
s.add_dependency(%q<net-scp>, [">= 1.0.0"])
|
45
|
+
s.add_dependency(%q<net-ssh-gateway>, [">= 1.0.0"])
|
46
|
+
s.add_dependency(%q<highline>, [">= 0"])
|
47
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
48
|
+
end
|
49
|
+
end
|
data/README.mdown
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
## Capistrano
|
2
|
+
|
3
|
+
Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH. It uses a simple DSL (borrowed in part from Rake, [[http://rake.rubyforge.org/]]) that allows you to define _tasks_, which may be applied to machines in certain roles. It also supports tunneling connections via some gateway machine to allow operations to be performed behind VPN's and firewalls.
|
4
|
+
|
5
|
+
Capistrano was originally designed to simplify and automate deployment of web applications to distributed environments, and originally came bundled with a set of tasks designed for deploying Rails applications.
|
6
|
+
|
7
|
+
## Documentation
|
8
|
+
|
9
|
+
* [[http://github.com/capistrano/capistrano/wiki/Documentation-v2.x]]
|
10
|
+
|
11
|
+
## DEPENDENCIES
|
12
|
+
|
13
|
+
* [[Net::SSH|http://net-ssh.rubyforge.org]]
|
14
|
+
* [[Net::SFTP|http://net-ssh.rubyforge.org]]
|
15
|
+
* [[Net::SCP|http://net-ssh.rubyforge.org]]
|
16
|
+
* [[Net::SSH::Gateway|http://net-ssh.rubyforge.org]]
|
17
|
+
* [[HighLine|http://highline.rubyforge.org]]
|
18
|
+
|
19
|
+
If you want to run the tests, you'll also need to have the following dependencies installed:
|
20
|
+
|
21
|
+
* Echoe (for the Rakefile)
|
22
|
+
* Mocha (http://mocha.rubyforge.org)
|
23
|
+
|
24
|
+
## ASSUMPTIONS
|
25
|
+
|
26
|
+
Capistrano is "opinionated software", which means it has very firm ideas about how things ought to be done, and tries to force those ideas on you. Some of the assumptions behind these opinions are:
|
27
|
+
|
28
|
+
* You are using SSH to access the remote servers.
|
29
|
+
* You either have the same password to all target machines, or you have public keys in place to allow passwordless access to them.
|
30
|
+
|
31
|
+
Do not expect these assumptions to change.
|
32
|
+
|
33
|
+
## USAGE
|
34
|
+
|
35
|
+
In general, you'll use Capistrano as follows:
|
36
|
+
|
37
|
+
* Create a recipe file ("capfile" or "Capfile").
|
38
|
+
* Use the `cap` script to execute your recipe.
|
39
|
+
|
40
|
+
Use the `cap` script as follows:
|
41
|
+
|
42
|
+
cap sometask
|
43
|
+
|
44
|
+
By default, the script will look for a file called one of `capfile` or `Capfile`. The `someaction` text indicates which task to execute. You can do "cap -h" to see all the available options and "cap -T" to see all the available tasks.
|
45
|
+
|
46
|
+
## LICENSE:
|
47
|
+
|
48
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
49
|
+
a copy of this software and associated documentation files (the
|
50
|
+
'Software'), to deal in the Software without restriction, including
|
51
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
52
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
53
|
+
permit persons to whom the Software is furnished to do so, subject to
|
54
|
+
the following conditions:
|
55
|
+
|
56
|
+
The above copyright notice and this permission notice shall be
|
57
|
+
included in all copies or substantial portions of the Software.
|
58
|
+
|
59
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
60
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
61
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
62
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
63
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
64
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
65
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.21
|
data/bin/cap
ADDED
data/bin/capify
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Usage: #{File.basename($0)} [path]"
|
8
|
+
|
9
|
+
opts.on("-h", "--help", "Displays this help info") do
|
10
|
+
puts opts
|
11
|
+
exit 0
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
opts.parse!(ARGV)
|
16
|
+
rescue OptionParser::ParseError => e
|
17
|
+
warn e.message
|
18
|
+
puts opts
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if ARGV.empty?
|
24
|
+
abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
|
25
|
+
elsif !File.exists?(ARGV.first)
|
26
|
+
abort "`#{ARGV.first}' does not exist."
|
27
|
+
elsif !File.directory?(ARGV.first)
|
28
|
+
abort "`#{ARGV.first}' is not a directory."
|
29
|
+
elsif ARGV.length > 1
|
30
|
+
abort "Too many arguments; please specify only the directory to capify."
|
31
|
+
end
|
32
|
+
|
33
|
+
def unindent(string)
|
34
|
+
indentation = string[/\A\s*/]
|
35
|
+
string.strip.gsub(/^#{indentation}/, "")
|
36
|
+
end
|
37
|
+
|
38
|
+
files = {
|
39
|
+
"Capfile" => unindent(<<-FILE),
|
40
|
+
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
|
41
|
+
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
|
42
|
+
|
43
|
+
load 'config/deploy' # remove this line to skip loading any of the default tasks
|
44
|
+
FILE
|
45
|
+
|
46
|
+
"config/deploy.rb" => 'set :application, "set your application name here"
|
47
|
+
set :repository, "set your repository location here"
|
48
|
+
|
49
|
+
set :scm, :subversion
|
50
|
+
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
|
51
|
+
|
52
|
+
role :web, "your web-server here" # Your HTTP server, Apache/etc
|
53
|
+
role :app, "your app-server here" # This may be the same as your `Web` server
|
54
|
+
role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
|
55
|
+
role :db, "your slave db-server here"
|
56
|
+
|
57
|
+
# if you\'re still using the script/reaper helper you will need
|
58
|
+
# these http://github.com/rails/irs_process_scripts
|
59
|
+
|
60
|
+
# If you are using Passenger mod_rails uncomment this:
|
61
|
+
# namespace :deploy do
|
62
|
+
# task :start do ; end
|
63
|
+
# task :stop do ; end
|
64
|
+
# task :restart, :roles => :app, :except => { :no_release => true } do
|
65
|
+
# run "#{try_sudo} touch #{File.join(current_path,\'tmp\',\'restart.txt\')}"
|
66
|
+
# end
|
67
|
+
# end'}
|
68
|
+
|
69
|
+
base = ARGV.shift
|
70
|
+
files.each do |file, content|
|
71
|
+
file = File.join(base, file)
|
72
|
+
if File.exists?(file)
|
73
|
+
warn "[skip] '#{file}' already exists"
|
74
|
+
elsif File.exists?(file.downcase)
|
75
|
+
warn "[skip] '#{file.downcase}' exists, which could conflict with `#{file}'"
|
76
|
+
else
|
77
|
+
unless File.exists?(File.dirname(file))
|
78
|
+
puts "[add] making directory '#{File.dirname(file)}'"
|
79
|
+
FileUtils.mkdir(File.dirname(file))
|
80
|
+
end
|
81
|
+
puts "[add] writing '#{file}'"
|
82
|
+
File.open(file, "w") { |f| f.write(content) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
puts "[done] capified!"
|
data/lib/capistrano.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Capistrano
|
2
|
+
class Callback
|
3
|
+
attr_reader :source, :options, :only, :except
|
4
|
+
|
5
|
+
def initialize(source, options={})
|
6
|
+
@source = source
|
7
|
+
@options = options
|
8
|
+
@only = Array(options[:only]).map { |v| v.to_s }
|
9
|
+
@except = Array(options[:except]).map { |v| v.to_s }
|
10
|
+
end
|
11
|
+
|
12
|
+
def applies_to?(task)
|
13
|
+
if task && only.any?
|
14
|
+
return only.include?(task.fully_qualified_name)
|
15
|
+
elsif task && except.any?
|
16
|
+
return !except.include?(task.fully_qualified_name)
|
17
|
+
else
|
18
|
+
return true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ProcCallback < Callback
|
24
|
+
def call
|
25
|
+
source.call
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class TaskCallback < Callback
|
30
|
+
attr_reader :config
|
31
|
+
|
32
|
+
def initialize(config, source, options={})
|
33
|
+
super(source, options)
|
34
|
+
@config = config
|
35
|
+
end
|
36
|
+
|
37
|
+
def call
|
38
|
+
config.find_and_execute_task(source)
|
39
|
+
end
|
40
|
+
|
41
|
+
def applies_to?(task)
|
42
|
+
super && (task.nil? || task.fully_qualified_name != source.to_s)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'capistrano'
|
2
|
+
require 'capistrano/cli/execute'
|
3
|
+
require 'capistrano/cli/help'
|
4
|
+
require 'capistrano/cli/options'
|
5
|
+
require 'capistrano/cli/ui'
|
6
|
+
|
7
|
+
module Capistrano
|
8
|
+
# The CLI class encapsulates the behavior of capistrano when it is invoked
|
9
|
+
# as a command-line utility. This allows other programs to embed Capistrano
|
10
|
+
# and preserve its command-line semantics.
|
11
|
+
class CLI
|
12
|
+
# The array of (unparsed) command-line options
|
13
|
+
attr_reader :args
|
14
|
+
|
15
|
+
# Create a new CLI instance using the given array of command-line parameters
|
16
|
+
# to initialize it. By default, +ARGV+ is used, but you can specify a
|
17
|
+
# different set of parameters (such as when embedded cap in a program):
|
18
|
+
#
|
19
|
+
# require 'capistrano/cli'
|
20
|
+
# Capistrano::CLI.parse(%W(-vvvv -f config/deploy update_code)).execute!
|
21
|
+
#
|
22
|
+
# Note that you can also embed cap directly by creating a new Configuration
|
23
|
+
# instance and setting it up, The above snippet, redone using the
|
24
|
+
# Configuration class directly, would look like:
|
25
|
+
#
|
26
|
+
# require 'capistrano'
|
27
|
+
# require 'capistrano/cli'
|
28
|
+
# config = Capistrano::Configuration.new
|
29
|
+
# config.logger.level = Capistrano::Logger::TRACE
|
30
|
+
# config.set(:password) { Capistrano::CLI.password_prompt }
|
31
|
+
# config.load "config/deploy"
|
32
|
+
# config.update_code
|
33
|
+
#
|
34
|
+
# There may be times that you want/need the additional control offered by
|
35
|
+
# manipulating the Configuration directly, but generally interfacing with
|
36
|
+
# the CLI class is recommended.
|
37
|
+
def initialize(args)
|
38
|
+
@args = args.dup
|
39
|
+
$stdout.sync = true # so that Net::SSH prompts show up
|
40
|
+
end
|
41
|
+
|
42
|
+
# Mix-in the actual behavior
|
43
|
+
include Execute, Options, UI
|
44
|
+
include Help # needs to be included last, because it overrides some methods
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'capistrano/configuration'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
class CLI
|
5
|
+
module Execute
|
6
|
+
def self.included(base) #:nodoc:
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
# Invoke capistrano using the ARGV array as the option parameters. This
|
12
|
+
# is what the command-line capistrano utility does.
|
13
|
+
def execute
|
14
|
+
parse(ARGV).execute!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Using the options build when the command-line was parsed, instantiate
|
19
|
+
# a new Capistrano configuration, initialize it, and execute the
|
20
|
+
# requested actions.
|
21
|
+
#
|
22
|
+
# Returns the Configuration instance used, if successful.
|
23
|
+
def execute!
|
24
|
+
config = instantiate_configuration(options)
|
25
|
+
config.debug = options[:debug]
|
26
|
+
config.dry_run = options[:dry_run]
|
27
|
+
config.preserve_roles = options[:preserve_roles]
|
28
|
+
config.logger.level = options[:verbose]
|
29
|
+
|
30
|
+
set_pre_vars(config)
|
31
|
+
load_recipes(config)
|
32
|
+
|
33
|
+
config.trigger(:load)
|
34
|
+
execute_requested_actions(config)
|
35
|
+
config.trigger(:exit)
|
36
|
+
|
37
|
+
config
|
38
|
+
rescue Exception => error
|
39
|
+
handle_error(error)
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute_requested_actions(config)
|
43
|
+
Array(options[:vars]).each { |name, value| config.set(name, value) }
|
44
|
+
|
45
|
+
Array(options[:actions]).each do |action|
|
46
|
+
config.find_and_execute_task(action, :before => :start, :after => :finish)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_pre_vars(config) #:nodoc:
|
51
|
+
config.set :password, options[:password]
|
52
|
+
Array(options[:pre_vars]).each { |name, value| config.set(name, value) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_recipes(config) #:nodoc:
|
56
|
+
# load the standard recipe definition
|
57
|
+
config.load "standard"
|
58
|
+
|
59
|
+
# load systemwide config/recipe definition
|
60
|
+
config.load(options[:sysconf]) if options[:sysconf] && File.file?(options[:sysconf])
|
61
|
+
|
62
|
+
# load user config/recipe definition
|
63
|
+
config.load(options[:dotfile]) if options[:dotfile] && File.file?(options[:dotfile])
|
64
|
+
|
65
|
+
Array(options[:recipes]).each { |recipe| config.load(recipe) }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Primarily useful for testing, but subclasses of CLI could conceivably
|
69
|
+
# override this method to return a Configuration subclass or replacement.
|
70
|
+
def instantiate_configuration(options={}) #:nodoc:
|
71
|
+
Capistrano::Configuration.new(options)
|
72
|
+
end
|
73
|
+
|
74
|
+
def handle_error(error) #:nodoc:
|
75
|
+
case error
|
76
|
+
when Net::SSH::AuthenticationFailed
|
77
|
+
abort "authentication failed for `#{error.message}'"
|
78
|
+
when Capistrano::Error
|
79
|
+
abort(error.message)
|
80
|
+
else raise error
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|