mbailey-capistrano 2.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +761 -0
- data/Manifest +104 -0
- data/README.rdoc +66 -0
- data/Rakefile +34 -0
- data/bin/cap +4 -0
- data/bin/capify +78 -0
- data/examples/sample.rb +14 -0
- data/lib/capistrano/callback.rb +45 -0
- data/lib/capistrano/cli/execute.rb +84 -0
- data/lib/capistrano/cli/help.rb +125 -0
- data/lib/capistrano/cli/help.txt +75 -0
- data/lib/capistrano/cli/options.rb +224 -0
- data/lib/capistrano/cli/ui.rb +40 -0
- data/lib/capistrano/cli.rb +47 -0
- data/lib/capistrano/command.rb +283 -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 +293 -0
- data/lib/capistrano/configuration/callbacks.rb +148 -0
- data/lib/capistrano/configuration/connections.rb +200 -0
- data/lib/capistrano/configuration/execution.rb +132 -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 +85 -0
- data/lib/capistrano/configuration/variables.rb +127 -0
- data/lib/capistrano/configuration.rb +43 -0
- data/lib/capistrano/errors.rb +15 -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/dependencies.rb +44 -0
- data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -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 +83 -0
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
- data/lib/capistrano/recipes/deploy/scm/git.rb +271 -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 +133 -0
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
- data/lib/capistrano/recipes/deploy/scm.rb +19 -0
- data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -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 +56 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/deploy.rb +562 -0
- data/lib/capistrano/recipes/standard.rb +37 -0
- data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
- data/lib/capistrano/recipes/upgrade.rb +33 -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 +99 -0
- data/lib/capistrano/task_definition.rb +70 -0
- data/lib/capistrano/transfer.rb +216 -0
- data/lib/capistrano/version.rb +18 -0
- data/lib/capistrano.rb +2 -0
- data/setup.rb +1346 -0
- data/test/cli/execute_test.rb +132 -0
- data/test/cli/help_test.rb +165 -0
- data/test/cli/options_test.rb +317 -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 +224 -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 +121 -0
- data/test/configuration/variables_test.rb +184 -0
- data/test/configuration_test.rb +88 -0
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +114 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +55 -0
- data/test/deploy/scm/git_test.rb +167 -0
- data/test/deploy/scm/mercurial_test.rb +129 -0
- data/test/deploy/strategy/copy_test.rb +258 -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 +104 -0
- data/test/task_definition_test.rb +101 -0
- data/test/transfer_test.rb +160 -0
- data/test/utils.rb +38 -0
- metadata +205 -0
@@ -0,0 +1,216 @@
|
|
1
|
+
require 'net/scp'
|
2
|
+
require 'net/sftp'
|
3
|
+
|
4
|
+
require 'capistrano/processable'
|
5
|
+
|
6
|
+
module Capistrano
|
7
|
+
class Transfer
|
8
|
+
include Processable
|
9
|
+
|
10
|
+
def self.process(direction, from, to, sessions, options={}, &block)
|
11
|
+
new(direction, from, to, sessions, options, &block).process!
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :sessions
|
15
|
+
attr_reader :options
|
16
|
+
attr_reader :callback
|
17
|
+
|
18
|
+
attr_reader :transport
|
19
|
+
attr_reader :direction
|
20
|
+
attr_reader :from
|
21
|
+
attr_reader :to
|
22
|
+
|
23
|
+
attr_reader :logger
|
24
|
+
attr_reader :transfers
|
25
|
+
|
26
|
+
def initialize(direction, from, to, sessions, options={}, &block)
|
27
|
+
@direction = direction
|
28
|
+
@from = from
|
29
|
+
@to = to
|
30
|
+
@sessions = sessions
|
31
|
+
@options = options
|
32
|
+
@callback = block
|
33
|
+
|
34
|
+
@transport = options.fetch(:via, :sftp)
|
35
|
+
@logger = options.delete(:logger)
|
36
|
+
|
37
|
+
@session_map = {}
|
38
|
+
|
39
|
+
prepare_transfers
|
40
|
+
end
|
41
|
+
|
42
|
+
def process!
|
43
|
+
loop do
|
44
|
+
begin
|
45
|
+
break unless process_iteration { active? }
|
46
|
+
rescue Exception => error
|
47
|
+
if error.respond_to?(:session)
|
48
|
+
handle_error(error)
|
49
|
+
else
|
50
|
+
raise
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
failed = transfers.select { |txfr| txfr[:failed] }
|
56
|
+
if failed.any?
|
57
|
+
hosts = failed.map { |txfr| txfr[:server] }
|
58
|
+
errors = failed.map { |txfr| "#{txfr[:error]} (#{txfr[:error].message})" }.uniq.join(", ")
|
59
|
+
error = TransferError.new("#{operation} via #{transport} failed on #{hosts.join(',')}: #{errors}")
|
60
|
+
error.hosts = hosts
|
61
|
+
|
62
|
+
logger.important(error.message) if logger
|
63
|
+
raise error
|
64
|
+
end
|
65
|
+
|
66
|
+
logger.debug "#{transport} #{operation} complete" if logger
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def active?
|
71
|
+
transfers.any? { |transfer| transfer.active? }
|
72
|
+
end
|
73
|
+
|
74
|
+
def operation
|
75
|
+
"#{direction}load"
|
76
|
+
end
|
77
|
+
|
78
|
+
def sanitized_from
|
79
|
+
if from.responds_to?(:read)
|
80
|
+
"#<#{from.class}>"
|
81
|
+
else
|
82
|
+
from
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def sanitized_to
|
87
|
+
if to.responds_to?(:read)
|
88
|
+
"#<#{to.class}>"
|
89
|
+
else
|
90
|
+
to
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def session_map
|
97
|
+
@session_map
|
98
|
+
end
|
99
|
+
|
100
|
+
def prepare_transfers
|
101
|
+
logger.info "#{transport} #{operation} #{from} -> #{to}" if logger
|
102
|
+
|
103
|
+
@transfers = sessions.map do |session|
|
104
|
+
session_from = normalize(from, session)
|
105
|
+
session_to = normalize(to, session)
|
106
|
+
|
107
|
+
session_map[session] = case transport
|
108
|
+
when :sftp
|
109
|
+
prepare_sftp_transfer(session_from, session_to, session)
|
110
|
+
when :scp
|
111
|
+
prepare_scp_transfer(session_from, session_to, session)
|
112
|
+
else
|
113
|
+
raise ArgumentError, "unsupported transport type: #{transport.inspect}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def prepare_scp_transfer(from, to, session)
|
119
|
+
real_callback = callback || Proc.new do |channel, name, sent, total|
|
120
|
+
logger.trace "[#{channel[:host]}] #{name}" if logger && sent == 0
|
121
|
+
end
|
122
|
+
|
123
|
+
channel = case direction
|
124
|
+
when :up
|
125
|
+
session.scp.upload(from, to, options, &real_callback)
|
126
|
+
when :down
|
127
|
+
session.scp.download(from, to, options, &real_callback)
|
128
|
+
else
|
129
|
+
raise ArgumentError, "unsupported transfer direction: #{direction.inspect}"
|
130
|
+
end
|
131
|
+
|
132
|
+
channel[:server] = session.xserver
|
133
|
+
channel[:host] = session.xserver.host
|
134
|
+
|
135
|
+
return channel
|
136
|
+
end
|
137
|
+
|
138
|
+
class SFTPTransferWrapper
|
139
|
+
attr_reader :operation
|
140
|
+
|
141
|
+
def initialize(session, &callback)
|
142
|
+
session.sftp(false).connect do |sftp|
|
143
|
+
@operation = callback.call(sftp)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def active?
|
148
|
+
@operation.nil? || @operation.active?
|
149
|
+
end
|
150
|
+
|
151
|
+
def [](key)
|
152
|
+
@operation[key]
|
153
|
+
end
|
154
|
+
|
155
|
+
def []=(key, value)
|
156
|
+
@operation[key] = value
|
157
|
+
end
|
158
|
+
|
159
|
+
def abort!
|
160
|
+
@operation.abort!
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def prepare_sftp_transfer(from, to, session)
|
165
|
+
SFTPTransferWrapper.new(session) do |sftp|
|
166
|
+
real_callback = Proc.new do |event, op, *args|
|
167
|
+
if callback
|
168
|
+
callback.call(event, op, *args)
|
169
|
+
elsif event == :open
|
170
|
+
logger.trace "[#{op[:host]}] #{args[0].remote}"
|
171
|
+
elsif event == :finish
|
172
|
+
logger.trace "[#{op[:host]}] done"
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
opts = options.dup
|
177
|
+
opts[:properties] = (opts[:properties] || {}).merge(
|
178
|
+
:server => session.xserver,
|
179
|
+
:host => session.xserver.host)
|
180
|
+
|
181
|
+
case direction
|
182
|
+
when :up
|
183
|
+
sftp.upload(from, to, opts, &real_callback)
|
184
|
+
when :down
|
185
|
+
sftp.download(from, to, opts, &real_callback)
|
186
|
+
else
|
187
|
+
raise ArgumentError, "unsupported transfer direction: #{direction.inspect}"
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def normalize(argument, session)
|
193
|
+
if argument.is_a?(String)
|
194
|
+
argument.gsub(/\$CAPISTRANO:HOST\$/, session.xserver.host)
|
195
|
+
elsif argument.respond_to?(:read)
|
196
|
+
pos = argument.pos
|
197
|
+
clone = StringIO.new(argument.read)
|
198
|
+
clone.pos = argument.pos = pos
|
199
|
+
clone
|
200
|
+
else
|
201
|
+
argument
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def handle_error(error)
|
206
|
+
transfer = session_map[error.session]
|
207
|
+
transfer[:error] = error
|
208
|
+
transfer[:failed] = true
|
209
|
+
|
210
|
+
case transport
|
211
|
+
when :sftp then transfer.abort!
|
212
|
+
when :scp then transfer.close
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/ssh/version'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
|
5
|
+
# Describes the current version of Capistrano.
|
6
|
+
class Version < Net::SSH::Version
|
7
|
+
MAJOR = 2
|
8
|
+
MINOR = 5
|
9
|
+
TINY = 5
|
10
|
+
|
11
|
+
# The current version, as a Version instance
|
12
|
+
CURRENT = new(MAJOR, MINOR, TINY)
|
13
|
+
|
14
|
+
# The current version, as a String instance
|
15
|
+
STRING = CURRENT.to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/lib/capistrano.rb
ADDED