capistrano 2.15.11 → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +17 -8
  3. data/Gemfile +1 -12
  4. data/LICENSE.txt +18 -0
  5. data/README.md +65 -68
  6. data/Rakefile +4 -10
  7. data/bin/cap +2 -3
  8. data/bin/capify +7 -91
  9. data/capistrano.gemspec +20 -34
  10. data/lib/Capfile +2 -0
  11. data/lib/capistrano/application.rb +28 -0
  12. data/lib/capistrano/bundler.rb +1 -0
  13. data/lib/capistrano/configuration/question.rb +42 -0
  14. data/lib/capistrano/configuration/server.rb +24 -0
  15. data/lib/capistrano/configuration/servers.rb +43 -95
  16. data/lib/capistrano/configuration.rb +81 -44
  17. data/lib/capistrano/console.rb +1 -0
  18. data/lib/capistrano/defaults.rb +11 -0
  19. data/lib/capistrano/deploy.rb +3 -0
  20. data/lib/capistrano/dotfile.rb +3 -0
  21. data/lib/capistrano/dsl/env.rb +57 -0
  22. data/lib/capistrano/dsl/paths.rb +74 -0
  23. data/lib/capistrano/dsl/stages.rb +15 -0
  24. data/lib/capistrano/dsl/task_enhancements.rb +15 -0
  25. data/lib/capistrano/dsl.rb +38 -0
  26. data/lib/capistrano/git.rb +1 -0
  27. data/lib/capistrano/i18n.rb +33 -0
  28. data/lib/capistrano/install.rb +1 -0
  29. data/lib/capistrano/setup.rb +17 -0
  30. data/lib/capistrano/tasks/bundler.rake +13 -0
  31. data/lib/capistrano/tasks/console.rake +21 -0
  32. data/lib/capistrano/tasks/deploy.rake +153 -0
  33. data/lib/capistrano/tasks/framework.rake +45 -0
  34. data/lib/capistrano/tasks/git.rake +65 -0
  35. data/lib/capistrano/tasks/install.rake +39 -0
  36. data/lib/capistrano/templates/Capfile +43 -0
  37. data/lib/capistrano/templates/deploy.rb.erb +17 -0
  38. data/lib/capistrano/templates/stage.rb.erb +20 -0
  39. data/lib/capistrano/version.rb +1 -11
  40. data/lib/capistrano.rb +9 -3
  41. data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
  42. data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
  43. data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
  44. data/spec/lib/capistrano/configuration_spec.rb +80 -0
  45. data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
  46. data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
  47. data/spec/lib/capistrano/dsl_spec.rb +51 -0
  48. data/spec/lib/capistrano_spec.rb +8 -0
  49. data/spec/spec_helper.rb +14 -0
  50. metadata +89 -215
  51. data/.travis.yml +0 -9
  52. data/CHANGELOG +0 -1203
  53. data/lib/capistrano/callback.rb +0 -45
  54. data/lib/capistrano/cli/execute.rb +0 -85
  55. data/lib/capistrano/cli/help.rb +0 -125
  56. data/lib/capistrano/cli/help.txt +0 -81
  57. data/lib/capistrano/cli/options.rb +0 -243
  58. data/lib/capistrano/cli/ui.rb +0 -40
  59. data/lib/capistrano/cli.rb +0 -47
  60. data/lib/capistrano/command.rb +0 -303
  61. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
  62. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  63. data/lib/capistrano/configuration/actions/invocation.rb +0 -329
  64. data/lib/capistrano/configuration/alias_task.rb +0 -26
  65. data/lib/capistrano/configuration/callbacks.rb +0 -147
  66. data/lib/capistrano/configuration/connections.rb +0 -237
  67. data/lib/capistrano/configuration/execution.rb +0 -142
  68. data/lib/capistrano/configuration/loading.rb +0 -205
  69. data/lib/capistrano/configuration/log_formatters.rb +0 -75
  70. data/lib/capistrano/configuration/namespaces.rb +0 -223
  71. data/lib/capistrano/configuration/roles.rb +0 -83
  72. data/lib/capistrano/configuration/variables.rb +0 -127
  73. data/lib/capistrano/errors.rb +0 -19
  74. data/lib/capistrano/ext/multistage.rb +0 -67
  75. data/lib/capistrano/ext/string.rb +0 -5
  76. data/lib/capistrano/extensions.rb +0 -57
  77. data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
  78. data/lib/capistrano/logger.rb +0 -166
  79. data/lib/capistrano/processable.rb +0 -55
  80. data/lib/capistrano/recipes/compat.rb +0 -32
  81. data/lib/capistrano/recipes/deploy/assets.rb +0 -202
  82. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  83. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
  84. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
  85. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  86. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
  87. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  88. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
  89. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
  90. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
  91. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
  92. data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
  93. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
  94. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
  95. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  96. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
  97. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  98. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
  99. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  100. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  101. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
  102. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
  103. data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
  104. data/lib/capistrano/recipes/deploy.rb +0 -625
  105. data/lib/capistrano/recipes/standard.rb +0 -37
  106. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  107. data/lib/capistrano/role.rb +0 -102
  108. data/lib/capistrano/server_definition.rb +0 -56
  109. data/lib/capistrano/shell.rb +0 -265
  110. data/lib/capistrano/ssh.rb +0 -95
  111. data/lib/capistrano/task_definition.rb +0 -77
  112. data/lib/capistrano/transfer.rb +0 -218
  113. data/test/cli/execute_test.rb +0 -132
  114. data/test/cli/help_test.rb +0 -165
  115. data/test/cli/options_test.rb +0 -329
  116. data/test/cli/ui_test.rb +0 -28
  117. data/test/cli_test.rb +0 -17
  118. data/test/command_test.rb +0 -322
  119. data/test/configuration/actions/file_transfer_test.rb +0 -61
  120. data/test/configuration/actions/inspect_test.rb +0 -76
  121. data/test/configuration/actions/invocation_test.rb +0 -306
  122. data/test/configuration/alias_task_test.rb +0 -118
  123. data/test/configuration/callbacks_test.rb +0 -201
  124. data/test/configuration/connections_test.rb +0 -439
  125. data/test/configuration/execution_test.rb +0 -175
  126. data/test/configuration/loading_test.rb +0 -148
  127. data/test/configuration/namespace_dsl_test.rb +0 -332
  128. data/test/configuration/roles_test.rb +0 -157
  129. data/test/configuration/servers_test.rb +0 -183
  130. data/test/configuration/variables_test.rb +0 -190
  131. data/test/configuration_test.rb +0 -77
  132. data/test/deploy/local_dependency_test.rb +0 -76
  133. data/test/deploy/remote_dependency_test.rb +0 -146
  134. data/test/deploy/scm/accurev_test.rb +0 -23
  135. data/test/deploy/scm/base_test.rb +0 -55
  136. data/test/deploy/scm/bzr_test.rb +0 -51
  137. data/test/deploy/scm/darcs_test.rb +0 -37
  138. data/test/deploy/scm/git_test.rb +0 -274
  139. data/test/deploy/scm/mercurial_test.rb +0 -134
  140. data/test/deploy/scm/none_test.rb +0 -35
  141. data/test/deploy/scm/perforce_test.rb +0 -23
  142. data/test/deploy/scm/subversion_test.rb +0 -68
  143. data/test/deploy/strategy/copy_test.rb +0 -360
  144. data/test/extensions_test.rb +0 -69
  145. data/test/fixtures/cli_integration.rb +0 -5
  146. data/test/fixtures/config.rb +0 -5
  147. data/test/fixtures/custom.rb +0 -3
  148. data/test/logger_formatting_test.rb +0 -149
  149. data/test/logger_test.rb +0 -134
  150. data/test/recipes_test.rb +0 -25
  151. data/test/role_test.rb +0 -11
  152. data/test/server_definition_test.rb +0 -121
  153. data/test/shell_test.rb +0 -96
  154. data/test/ssh_test.rb +0 -113
  155. data/test/task_definition_test.rb +0 -117
  156. data/test/transfer_test.rb +0 -168
  157. data/test/utils.rb +0 -37
  158. data/test/version_test.rb +0 -11
@@ -1,303 +0,0 @@
1
- require 'benchmark'
2
- require 'capistrano/errors'
3
- require 'capistrano/processable'
4
-
5
- module Capistrano
6
-
7
- # This class encapsulates a single command to be executed on a set of remote
8
- # machines, in parallel.
9
- class Command
10
- include Processable
11
-
12
- class Tree
13
- attr_reader :configuration
14
- attr_reader :branches
15
- attr_reader :fallback
16
-
17
- include Enumerable
18
-
19
- class Branch
20
- attr_accessor :command, :callback, :condition
21
- attr_reader :options
22
-
23
- def initialize(command, options, callback)
24
- @command = command.strip.gsub(/\r?\n/, "\\\n")
25
- @callback = callback || Capistrano::Configuration.default_io_proc
26
- @options = options
27
- @skip = false
28
- end
29
-
30
- def last?
31
- options[:last]
32
- end
33
-
34
- def skip?
35
- @skip
36
- end
37
-
38
- def skip!
39
- @skip = true
40
- end
41
-
42
- def match(server)
43
- true
44
- end
45
-
46
- def to_s(parallel=false)
47
- if parallel && @condition
48
- "#{condition.inspect} :: #{command.inspect}"
49
- else
50
- command.inspect
51
- end
52
- end
53
- end
54
-
55
- class ConditionBranch < Branch
56
- attr_accessor :configuration
57
-
58
- class Evaluator
59
- attr_reader :configuration, :condition, :server
60
-
61
- def initialize(config, condition, server)
62
- @configuration = config
63
- @condition = condition
64
- @server = server
65
- end
66
-
67
- def in?(role)
68
- configuration.roles[role].include?(server)
69
- end
70
-
71
- def result
72
- eval(condition, binding)
73
- end
74
-
75
- def method_missing(sym, *args, &block)
76
- if server.respond_to?(sym)
77
- server.send(sym, *args, &block)
78
- elsif configuration.respond_to?(sym)
79
- configuration.send(sym, *args, &block)
80
- else
81
- super
82
- end
83
- end
84
- end
85
-
86
- def initialize(configuration, condition, command, options, callback)
87
- @configuration = configuration
88
- @condition = condition
89
- super(command, options, callback)
90
- end
91
-
92
- def match(server)
93
- Evaluator.new(configuration, condition, server).result
94
- end
95
- end
96
-
97
- class ElseBranch < Branch
98
- def initialize(command, options, callback)
99
- @condition = "else"
100
- super(command, options, callback)
101
- end
102
- end
103
-
104
- def initialize(config)
105
- @configuration = config
106
- @branches = []
107
- yield self if block_given?
108
- end
109
-
110
- def when(condition, command, options={}, &block)
111
- branches << ConditionBranch.new(configuration, condition, command, options, block)
112
- end
113
-
114
- def else(command, &block)
115
- @fallback = ElseBranch.new(command, {}, block)
116
- end
117
-
118
- def branches_for(server)
119
- seen_last = false
120
- matches = branches.select do |branch|
121
- success = !seen_last && !branch.skip? && branch.match(server)
122
- seen_last = success && branch.last?
123
- success
124
- end
125
-
126
- matches << fallback if matches.empty? && fallback
127
- return matches
128
- end
129
-
130
- def each
131
- branches.each { |branch| yield branch }
132
- yield fallback if fallback
133
- return self
134
- end
135
- end
136
-
137
- attr_reader :tree, :sessions, :options
138
-
139
- def self.process(tree, sessions, options={})
140
- new(tree, sessions, options).process!
141
- end
142
-
143
- # Instantiates a new command object. The +command+ must be a string
144
- # containing the command to execute. +sessions+ is an array of Net::SSH
145
- # session instances, and +options+ must be a hash containing any of the
146
- # following keys:
147
- #
148
- # * +logger+: (optional), a Capistrano::Logger instance
149
- # * +data+: (optional), a string to be sent to the command via it's stdin
150
- # * +env+: (optional), a string or hash to be interpreted as environment
151
- # variables that should be defined for this command invocation.
152
- def initialize(tree, sessions, options={}, &block)
153
- if String === tree
154
- tree = Tree.new(nil) { |t| t.else(tree, &block) }
155
- elsif block
156
- raise ArgumentError, "block given with tree argument"
157
- end
158
-
159
- @tree = tree
160
- @sessions = sessions
161
- @options = options
162
- @channels = open_channels
163
- end
164
-
165
- # Processes the command in parallel on all specified hosts. If the command
166
- # fails (non-zero return code) on any of the hosts, this will raise a
167
- # Capistrano::CommandError.
168
- def process!
169
- elapsed = Benchmark.realtime do
170
- loop do
171
- break unless process_iteration { @channels.any? { |ch| !ch[:closed] } }
172
- end
173
- end
174
-
175
- logger.trace "command finished in #{(elapsed * 1000).round}ms" if logger
176
-
177
- if (failed = @channels.select { |ch| ch[:status] != 0 }).any?
178
- commands = failed.inject({}) { |map, ch| (map[ch[:command]] ||= []) << ch[:server]; map }
179
- message = commands.map { |command, list| "#{command.inspect} on #{list.join(',')}" }.join("; ")
180
- error = CommandError.new("failed: #{message}")
181
- error.hosts = commands.values.flatten
182
- raise error
183
- end
184
-
185
- self
186
- end
187
-
188
- # Force the command to stop processing, by closing all open channels
189
- # associated with this command.
190
- def stop!
191
- @channels.each do |ch|
192
- ch.close unless ch[:closed]
193
- end
194
- end
195
-
196
- private
197
-
198
- def logger
199
- options[:logger]
200
- end
201
-
202
- def open_channels
203
- sessions.map do |session|
204
- server = session.xserver
205
- tree.branches_for(server).map do |branch|
206
- session.open_channel do |channel|
207
- channel[:server] = server
208
- channel[:host] = server.host
209
- channel[:options] = options
210
- channel[:branch] = branch
211
-
212
- request_pty_if_necessary(channel) do |ch, success|
213
- if success
214
- logger.trace "executing command", ch[:server] if logger
215
- cmd = replace_placeholders(channel[:branch].command, ch)
216
-
217
- if options[:shell] == false
218
- shell = nil
219
- else
220
- shell = "#{options[:shell] || "sh"} -c"
221
- cmd = cmd.gsub(/'/) { |m| "'\\''" }
222
- cmd = "'#{cmd}'"
223
- end
224
-
225
- command_line = [environment, shell, cmd].compact.join(" ")
226
- ch[:command] = command_line
227
-
228
- ch.exec(command_line)
229
- ch.send_data(options[:data]) if options[:data]
230
- ch.eof! if options[:eof]
231
- else
232
- # just log it, don't actually raise an exception, since the
233
- # process method will see that the status is not zero and will
234
- # raise an exception then.
235
- logger.important "could not open channel", ch[:server] if logger
236
- ch.close
237
- end
238
- end
239
-
240
- channel.on_data do |ch, data|
241
- ch[:branch].callback[ch, :out, data]
242
- end
243
-
244
- channel.on_extended_data do |ch, type, data|
245
- ch[:branch].callback[ch, :err, data]
246
- end
247
-
248
- channel.on_request("exit-status") do |ch, data|
249
- ch[:status] = data.read_long
250
- end
251
-
252
- channel.on_request("exit-signal") do |ch, data|
253
- if logger
254
- exit_signal = data.read_string
255
- logger.important "command received signal #{exit_signal}", ch[:server]
256
- end
257
- end
258
-
259
- channel.on_close do |ch|
260
- ch[:closed] = true
261
- end
262
- end
263
- end
264
- end.flatten
265
- end
266
-
267
- def request_pty_if_necessary(channel)
268
- if options[:pty]
269
- channel.request_pty do |ch, success|
270
- yield ch, success
271
- end
272
- else
273
- yield channel, true
274
- end
275
- end
276
-
277
- def replace_placeholders(command, channel)
278
- roles = @tree.configuration && @tree.configuration.role_names_for_host(channel[:server])
279
- command = command.gsub(/\$CAPISTRANO:HOST\$/, channel[:host])
280
- command.gsub!(/\$CAPISTRANO:HOSTROLES\$/, roles.join(',')) if roles
281
- command
282
- end
283
-
284
- # prepare a space-separated sequence of variables assignments
285
- # intended to be prepended to a command, so the shell sets
286
- # the environment before running the command.
287
- # i.e.: options[:env] = {'PATH' => '/opt/ruby/bin:$PATH',
288
- # 'TEST' => '( "quoted" )'}
289
- # environment returns:
290
- # "env TEST=(\ \"quoted\"\ ) PATH=/opt/ruby/bin:$PATH"
291
- def environment
292
- return if options[:env].nil? || options[:env].empty?
293
- @environment ||= if String === options[:env]
294
- "env #{options[:env]}"
295
- else
296
- options[:env].inject("env") do |string, (name, value)|
297
- value = value.to_s.gsub(/[ "]/) { |m| "\\#{m}" }
298
- string << " #{name}=#{value}"
299
- end
300
- end
301
- end
302
- end
303
- end
@@ -1,50 +0,0 @@
1
- require 'capistrano/transfer'
2
-
3
- module Capistrano
4
- class Configuration
5
- module Actions
6
- module FileTransfer
7
-
8
- # Store the given data at the given location on all servers targetted
9
- # by the current task. If <tt>:mode</tt> is specified it is used to
10
- # set the mode on the file.
11
- def put(data, path, options={})
12
- opts = options.dup
13
- upload(StringIO.new(data), path, opts)
14
- end
15
-
16
- # Get file remote_path from FIRST server targeted by
17
- # the current task and transfer it to local machine as path.
18
- #
19
- # get "#{deploy_to}/current/log/production.log", "log/production.log.web"
20
- def get(remote_path, path, options={}, &block)
21
- download(remote_path, path, options.merge(:once => true), &block)
22
- end
23
-
24
- def upload(from, to, options={}, &block)
25
- mode = options.delete(:mode)
26
- transfer(:up, from, to, options, &block)
27
- if mode
28
- mode = mode.is_a?(Numeric) ? mode.to_s(8) : mode.to_s
29
- run "chmod #{mode} #{to}", options
30
- end
31
- end
32
-
33
- def download(from, to, options={}, &block)
34
- transfer(:down, from, to, options, &block)
35
- end
36
-
37
- def transfer(direction, from, to, options={}, &block)
38
- if dry_run
39
- return logger.debug "transfering: #{[direction, from, to] * ', '}"
40
- end
41
- execute_on_servers(options) do |servers|
42
- targets = servers.map { |s| sessions[s] }
43
- Transfer.process(direction, from, to, targets, options.merge(:logger => logger), &block)
44
- end
45
- end
46
-
47
- end
48
- end
49
- end
50
- end
@@ -1,46 +0,0 @@
1
- require 'capistrano/errors'
2
-
3
- module Capistrano
4
- class Configuration
5
- module Actions
6
- module Inspect
7
-
8
- # Streams the result of the command from all servers that are the
9
- # target of the current task. All these streams will be joined into a
10
- # single one, so you can, say, watch 10 log files as though they were
11
- # one. Do note that this is quite expensive from a bandwidth
12
- # perspective, so use it with care.
13
- #
14
- # The command is invoked via #invoke_command.
15
- #
16
- # Usage:
17
- #
18
- # desc "Run a tail on multiple log files at the same time"
19
- # task :tail_fcgi, :roles => :app do
20
- # stream "tail -f #{shared_path}/log/fastcgi.crash.log"
21
- # end
22
- def stream(command, options={})
23
- invoke_command(command, options.merge(:eof => !command.include?(sudo))) do |ch, stream, out|
24
- puts out if stream == :out
25
- warn "[err :: #{ch[:server]}] #{out}" if stream == :err
26
- end
27
- end
28
-
29
- # Executes the given command on the first server targetted by the
30
- # current task, collects it's stdout into a string, and returns the
31
- # string. The command is invoked via #invoke_command.
32
- def capture(command, options={})
33
- output = ""
34
- invoke_command(command, options.merge(:once => true, :eof => !command.include?(sudo))) do |ch, stream, data|
35
- case stream
36
- when :out then output << data
37
- when :err then warn "[err :: #{ch[:server]}] #{data}"
38
- end
39
- end
40
- output
41
- end
42
-
43
- end
44
- end
45
- end
46
- end