capistrano-rbenv 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Capistrano::RbEnv::VERSION
17
17
 
18
18
  gem.add_dependency("capistrano")
19
+ gem.add_dependency("capistrano-platform-resources", ">= 0.1.0")
19
20
  gem.add_development_dependency("net-scp", "~> 1.0.4")
20
21
  gem.add_development_dependency("net-ssh", "~> 2.2.2")
21
22
  gem.add_development_dependency("vagrant", "~> 1.0.6")
@@ -1,5 +1,6 @@
1
1
  require "capistrano-rbenv/version"
2
2
  require "capistrano/configuration"
3
+ require "capistrano/configuration/resources/platform_resources"
3
4
  require "capistrano/recipes/deploy/scm"
4
5
 
5
6
  module Capistrano
@@ -18,7 +19,7 @@ module Capistrano
18
19
  File.join(rbenv_bin_path, "rbenv")
19
20
  }
20
21
  def rbenv_command(options={})
21
- environment = rbenv_environment.merge(options.fetch(:env, {}))
22
+ environment = _merge_environment(rbenv_environment, options.fetch(:env, {}))
22
23
  environment["RBENV_VERSION"] = options[:version] if options.key?(:version)
23
24
  if environment.empty?
24
25
  rbenv_bin
@@ -28,12 +29,10 @@ module Capistrano
28
29
  end
29
30
  end
30
31
  _cset(:rbenv_cmd) { rbenv_command(:version => rbenv_ruby_version) } # this declares RBENV_VERSION.
31
- _cset(:rbenv_environment) {
32
- {
33
- "RBENV_ROOT" => rbenv_path,
34
- "PATH" => [ rbenv_shims_path, rbenv_bin_path, "$PATH" ].join(":"),
35
- }
36
- }
32
+ _cset(:rbenv_environment) {{
33
+ "RBENV_ROOT" => rbenv_path,
34
+ "PATH" => [ rbenv_shims_path, rbenv_bin_path, "$PATH" ].join(":"),
35
+ }}
37
36
  _cset(:rbenv_repository, 'git://github.com/sstephenson/rbenv.git')
38
37
  _cset(:rbenv_branch, 'master')
39
38
 
@@ -62,13 +61,7 @@ module Capistrano
62
61
  if rbenv_ruby_dependencies.empty?
63
62
  false
64
63
  else
65
- status = case rbenv_platform
66
- when /(debian|ubuntu)/i
67
- capture("dpkg-query -s #{rbenv_ruby_dependencies.map { |x| x.dump }.join(" ")} 1>/dev/null 2>&1 || echo required")
68
- when /redhat/i
69
- capture("rpm -qi #{rbenv_ruby_dependencies.map { |x| x.dump }.join(" ")} 1>/dev/null 2>&1 || echo required")
70
- end
71
- true and (/required/i =~ status)
64
+ not(platform.packages.installed?(rbenv_ruby_dependencies))
72
65
  end
73
66
  }
74
67
 
@@ -77,6 +70,7 @@ module Capistrano
77
70
  #
78
71
  # skip installation if the requested version has been installed.
79
72
  #
73
+ reset!(:rbenv_ruby_versions)
80
74
  begin
81
75
  installed = rbenv_ruby_versions.include?(rbenv_ruby_version)
82
76
  rescue
@@ -132,10 +126,6 @@ module Capistrano
132
126
  plugins.update
133
127
  }
134
128
 
135
- def _setup_default_environment
136
- set(:default_environment, default_environment.merge(rbenv_environment))
137
- end
138
-
139
129
  _cset(:rbenv_setup_default_environment) {
140
130
  if exists?(:rbenv_define_default_environment)
141
131
  logger.info(":rbenv_define_default_environment has been deprecated. use :rbenv_setup_default_environment instead.")
@@ -147,23 +137,36 @@ module Capistrano
147
137
  # workaround for loading `capistrano-rbenv` later than `capistrano/ext/multistage`.
148
138
  # https://github.com/yyuu/capistrano-rbenv/pull/5
149
139
  if top.namespaces.key?(:multistage)
150
- after "multistage:ensure" do
151
- _setup_default_environment if rbenv_setup_default_environment
152
- end
140
+ after "multistage:ensure", "rbenv:setup_default_environment"
153
141
  else
154
142
  on :start do
155
143
  if top.namespaces.key?(:multistage)
156
144
  # workaround for loading `capistrano-rbenv` earlier than `capistrano/ext/multistage`.
157
145
  # https://github.com/yyuu/capistrano-rbenv/issues/7
158
- after "multistage:ensure" do
159
- _setup_default_environment if rbenv_setup_default_environment
160
- end
146
+ after "multistage:ensure", "rbenv:setup_default_environment"
161
147
  else
162
- _setup_default_environment if rbenv_setup_default_environment
148
+ setup_default_environment
163
149
  end
164
150
  end
165
151
  end
166
152
 
153
+ _cset(:rbenv_environment_join_keys, %w(DYLD_LIBRARY_PATH LD_LIBRARY_PATH MANPATH PATH))
154
+ def _merge_environment(x, y)
155
+ x.merge(y) { |key, x_val, y_val|
156
+ if rbenv_environment_join_keys.key?(key)
157
+ ( y_val.split(":") + x_val.split(":") ).uniq.join(":")
158
+ else
159
+ y_val
160
+ end
161
+ }
162
+ end
163
+
164
+ task(:setup_default_environment, :except => { :no_release => true }) {
165
+ if rbenv_setup_default_environment
166
+ set(:default_environment, _merge_environment(default_environment, rbenv_environment))
167
+ end
168
+ }
169
+
167
170
  desc("Purge rbenv.")
168
171
  task(:purge, :except => { :no_release => true }) {
169
172
  run("rm -rf #{rbenv_path.dump}")
@@ -257,46 +260,25 @@ module Capistrano
257
260
  end
258
261
  }
259
262
 
260
- _cset(:rbenv_platform) {
261
- capture((<<-EOS).gsub(/\s+/, ' ')).strip
262
- if test -f /etc/debian_version; then
263
- if test -f /etc/lsb-release && grep -i -q DISTRIB_ID=Ubuntu /etc/lsb-release; then
264
- echo ubuntu;
265
- else
266
- echo debian;
267
- fi;
268
- elif test -f /etc/redhat-release; then
269
- echo redhat;
270
- else
271
- echo unknown;
272
- fi;
273
- EOS
274
- }
263
+ _cset(:rbenv_platform) { fetch(:platform_identifier) }
275
264
  _cset(:rbenv_ruby_dependencies) {
276
- case rbenv_platform
277
- when /(debian|ubuntu)/i
265
+ case rbenv_platform.to_sym
266
+ when :debian, :ubuntu
278
267
  %w(git-core build-essential libreadline6-dev zlib1g-dev libssl-dev bison)
279
- when /redhat/i
268
+ when :redhat, :centos
280
269
  %w(git-core autoconf glibc-devel patch readline readline-devel zlib zlib-devel openssl bison)
281
270
  else
282
271
  []
283
272
  end
284
273
  }
285
274
  task(:dependencies, :except => { :no_release => true }) {
286
- unless rbenv_ruby_dependencies.empty?
287
- case rbenv_platform
288
- when /(debian|ubuntu)/i
289
- run("#{sudo} apt-get install -q -y #{rbenv_ruby_dependencies.map { |x| x.dump }.join(" ")}")
290
- when /redhat/i
291
- run("#{sudo} yum install -q -y #{rbenv_ruby_dependencies.map { |x| x.dump }.join(" ")}")
292
- end
293
- end
275
+ platform.packages.install(rbenv_ruby_dependencies)
294
276
  }
295
277
 
296
278
  _cset(:rbenv_ruby_versions) { rbenv.versions }
297
279
  desc("Build ruby within rbenv.")
298
280
  task(:build, :except => { :no_release => true }) {
299
- reset!(:rbenv_ruby_versions)
281
+ # reset!(:rbenv_ruby_versions)
300
282
  ruby = fetch(:rbenv_ruby_cmd, "ruby")
301
283
  if rbenv_ruby_version != "system" and not rbenv_ruby_versions.include?(rbenv_ruby_version)
302
284
  rbenv.install(rbenv_ruby_version)
@@ -328,31 +310,35 @@ module Capistrano
328
310
  invoke_command("#{rbenv_command} global #{version.dump}", options)
329
311
  end
330
312
 
331
- def local(version, options={})
313
+ def invoke_command_with_path(cmdline, options={})
332
314
  path = options.delete(:path)
333
- execute = []
334
- execute << "cd #{path.dump}" if path
335
- execute << "#{rbenv_command} local #{version.dump}"
336
- invoke_command(execute.join(" && "), options)
315
+ if path
316
+ chdir = "cd #{path.dump}"
317
+ via = options.delete(:via)
318
+ # as of Capistrano 2.14.2, `sudo()` cannot handle multiple command correctly.
319
+ if via == :sudo
320
+ invoke_command("#{chdir} && #{sudo} #{cmdline}", options)
321
+ else
322
+ invoke_command("#{chdir} && #{cmdline}", options.merge(:via => via))
323
+ end
324
+ else
325
+ invoke_command(cmdline, options)
326
+ end
327
+ end
328
+
329
+ def local(version, options={})
330
+ invoke_command_with_path("#{rbenv_command} local #{version.dump}", options)
337
331
  end
338
332
 
339
333
  def which(command, options={})
340
- path = options.delete(:path)
341
334
  version = ( options.delete(:version) || rbenv_ruby_version )
342
- execute = []
343
- execute << "cd #{path.dump}" if path
344
- execute << "#{rbenv_command(:version => version)} which #{command.dump}"
345
- capture(execute.join(" && "), options).strip
335
+ invoke_command_with_path("#{rbenv_command(:version => version)} which #{command.dump}", options)
346
336
  end
347
337
 
348
338
  def exec(command, options={})
349
339
  # users of rbenv.exec must sanitize their command line.
350
- path = options.delete(:path)
351
340
  version = ( options.delete(:version) || rbenv_ruby_version )
352
- execute = []
353
- execute << "cd #{path.dump}" if path
354
- execute << "#{rbenv_command(:version => version)} exec #{command}"
355
- invoke_command(execute.join(" && "), options)
341
+ invoke_command_with_path("#{rbenv_command(:version => version)} exec #{command}", options)
356
342
  end
357
343
 
358
344
  def versions(options={})
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module RbEnv
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  bundle exec vagrant up
4
4
  bundle exec cap test_all
5
- bundle exec vagrant destroy -f
5
+ bundle exec vagrant halt
6
6
 
7
7
  # vim:set ft=sh :
@@ -56,10 +56,10 @@ namespace(:test_default) {
56
56
  rbenv.exec("ruby -e 'exit(Dir.pwd==%{/}?0:1)'", :path => "/")
57
57
  }
58
58
 
59
- # task(:test_rbenv_exec_ruby_via_sudo_with_path) {
60
- # # capistrano does not provide safer way to invoke multiple commands via sudo.
61
- # rbenv.exec("ruby -e 'exit(Dir.pwd==%{/}&&Process.uid==0?0:1'", :path => "/", :via => :sudo )
62
- # }
59
+ task(:test_rbenv_exec_ruby_via_sudo_with_path) {
60
+ # capistrano does not provide safer way to invoke multiple commands via sudo.
61
+ rbenv.exec("ruby -e 'exit(Dir.pwd==%{/}&&Process.uid==0?0:1)'", :path => "/", :via => :sudo )
62
+ }
63
63
 
64
64
  ## via sudo
65
65
  task(:test_rbenv_exec_via_sudo) {
@@ -2,6 +2,6 @@
2
2
 
3
3
  bundle exec vagrant up
4
4
  bundle exec cap test_all
5
- bundle exec vagrant destroy -f
5
+ bundle exec vagrant halt
6
6
 
7
7
  # vim:set ft=sh :
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-rbenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-13 00:00:00.000000000 Z
12
+ date: 2013-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano-platform-resources
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.1.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.0
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: net-scp
32
48
  requirement: !ruby/object:Gem::Requirement