capistrano-rbenv 1.0.0rc1 → 1.0.0rc2
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/lib/capistrano-rbenv.rb +63 -42
- data/lib/capistrano-rbenv/version.rb +1 -1
- data/test/config/deploy.rb +97 -7
- metadata +2 -2
data/lib/capistrano-rbenv.rb
CHANGED
@@ -17,8 +17,22 @@ module Capistrano
|
|
17
17
|
_cset(:rbenv_bin) {
|
18
18
|
File.join(rbenv_bin_path, "rbenv")
|
19
19
|
}
|
20
|
-
|
21
|
-
|
20
|
+
def rbenv_command(options={})
|
21
|
+
environment = rbenv_environment.merge(options.fetch(:env, {}))
|
22
|
+
environment["RBENV_VERSION"] = options[:version] if options.key?(:version)
|
23
|
+
if environment.empty?
|
24
|
+
rbenv_bin
|
25
|
+
else
|
26
|
+
env = (["env"] + environment.map { |k, v| "#{k}=#{v.dump}" }).join(" ")
|
27
|
+
"#{env} #{rbenv_bin}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
_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
|
+
}
|
22
36
|
}
|
23
37
|
_cset(:rbenv_repository, 'git://github.com/sstephenson/rbenv.git')
|
24
38
|
_cset(:rbenv_branch, 'master')
|
@@ -60,13 +74,25 @@ module Capistrano
|
|
60
74
|
|
61
75
|
desc("Setup rbenv.")
|
62
76
|
task(:setup, :except => { :no_release => true }) {
|
77
|
+
#
|
78
|
+
# skip installation if the requested version has been installed.
|
79
|
+
#
|
80
|
+
begin
|
81
|
+
installed = rbenv_ruby_versions.include?(rbenv_ruby_version)
|
82
|
+
rescue
|
83
|
+
installed = false
|
84
|
+
end
|
85
|
+
_setup unless installed
|
86
|
+
configure if rbenv_setup_shell
|
87
|
+
setup_bundler if rbenv_install_bundler
|
88
|
+
}
|
89
|
+
after "deploy:setup", "rbenv:setup"
|
90
|
+
|
91
|
+
task(:_setup, :except => { :no_release => true }) {
|
63
92
|
dependencies if rbenv_install_dependencies
|
64
93
|
update
|
65
|
-
configure if rbenv_setup_shell
|
66
94
|
build
|
67
|
-
setup_bundler if rbenv_install_bundler
|
68
95
|
}
|
69
|
-
after 'deploy:setup', 'rbenv:setup'
|
70
96
|
|
71
97
|
def _update_repository(destination, options={})
|
72
98
|
configuration = Capistrano::Configuration.new()
|
@@ -106,10 +132,7 @@ module Capistrano
|
|
106
132
|
}
|
107
133
|
|
108
134
|
def _setup_default_environment
|
109
|
-
|
110
|
-
env["RBENV_ROOT"] = rbenv_path
|
111
|
-
env["PATH"] = [ rbenv_shims_path, rbenv_bin_path, env.fetch("PATH", "$PATH") ].join(":")
|
112
|
-
set(:default_environment, env)
|
135
|
+
set(:default_environment, default_environment.merge(rbenv_environment))
|
113
136
|
end
|
114
137
|
|
115
138
|
_cset(:rbenv_setup_default_environment) {
|
@@ -278,69 +301,66 @@ module Capistrano
|
|
278
301
|
rbenv.install(rbenv_ruby_version)
|
279
302
|
end
|
280
303
|
rbenv.exec("#{ruby} --version") # check if ruby is executable
|
281
|
-
rbenv.global(rbenv_ruby_version)
|
304
|
+
rbenv.global(rbenv_ruby_version) if fetch(:rbenv_setup_global_version, true)
|
282
305
|
}
|
283
306
|
|
284
307
|
_cset(:rbenv_bundler_gem, 'bundler')
|
285
308
|
task(:setup_bundler, :except => { :no_release => true }) {
|
286
309
|
gem = "#{rbenv_cmd} exec gem"
|
287
|
-
if
|
288
|
-
|
289
|
-
|
290
|
-
i = "-v #{v} #{rbenv_bundler_gem}"
|
310
|
+
if version = fetch(:rbenv_bundler_version, nil)
|
311
|
+
query_args = "-i -n #{rbenv_bundler_gem.dump} -v #{version.dump}"
|
312
|
+
install_args = "-v #{version.dump} #{rbenv_bundler_gem.dump}"
|
291
313
|
else
|
292
|
-
|
293
|
-
|
294
|
-
i = "#{rbenv_bundler_gem}"
|
314
|
+
query_args = "-i -n #{rbenv_bundler_gem.dump}"
|
315
|
+
install_args = "#{rbenv_bundler_gem.dump}"
|
295
316
|
end
|
296
|
-
run("unset -v GEM_HOME; #{gem} query #{
|
317
|
+
run("unset -v GEM_HOME; #{gem} query #{query_args} 2>/dev/null || #{gem} install -q #{install_args}")
|
297
318
|
rbenv.rehash
|
298
319
|
run("#{bundle_cmd} version")
|
299
320
|
}
|
300
321
|
|
301
322
|
# call `rbenv rehash` to update shims.
|
302
323
|
def rehash(options={})
|
303
|
-
|
324
|
+
invoke_command("#{rbenv_command} rehash", options)
|
304
325
|
end
|
305
326
|
|
306
327
|
def global(version, options={})
|
307
|
-
|
328
|
+
invoke_command("#{rbenv_command} global #{version.dump}", options)
|
308
329
|
end
|
309
330
|
|
310
331
|
def local(version, options={})
|
311
332
|
path = options.delete(:path)
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
end
|
333
|
+
execute = []
|
334
|
+
execute << "cd #{path.dump}" if path
|
335
|
+
execute << "#{rbenv_command} local #{version.dump}"
|
336
|
+
invoke_command(execute.join(" && "), options)
|
317
337
|
end
|
318
338
|
|
319
339
|
def which(command, options={})
|
320
340
|
path = options.delete(:path)
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
341
|
+
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
|
326
346
|
end
|
327
347
|
|
328
348
|
def exec(command, options={})
|
329
349
|
# users of rbenv.exec must sanitize their command line.
|
330
350
|
path = options.delete(:path)
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
351
|
+
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)
|
336
356
|
end
|
337
357
|
|
338
358
|
def versions(options={})
|
339
|
-
capture("#{
|
359
|
+
capture("#{rbenv_command} versions --bare", options).split(/(?:\r?\n)+/)
|
340
360
|
end
|
341
361
|
|
342
362
|
def available_versions(options={})
|
343
|
-
capture("#{
|
363
|
+
capture("#{rbenv_command} install --complete", options).split(/(?:\r?\n)+/)
|
344
364
|
end
|
345
365
|
|
346
366
|
_cset(:rbenv_install_ruby_threads) {
|
@@ -348,15 +368,16 @@ module Capistrano
|
|
348
368
|
}
|
349
369
|
# create build processes as many as processor count
|
350
370
|
_cset(:rbenv_make_options) { "-j #{rbenv_install_ruby_threads}" }
|
371
|
+
_cset(:rbenv_configure_options, nil)
|
351
372
|
def install(version, options={})
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
373
|
+
environment = {}
|
374
|
+
environment["CONFIGURE_OPTS"] = rbenv_configure_options.to_s if rbenv_configure_options
|
375
|
+
environment["MAKE_OPTS"] = rbenv_make_options.to_s if rbenv_make_options
|
376
|
+
invoke_command("#{rbenv_command(:env => environment)} install #{version.dump}", options)
|
356
377
|
end
|
357
378
|
|
358
379
|
def uninstall(version, options={})
|
359
|
-
|
380
|
+
invoke_command("#{rbenv_command} uninstall -f #{version.dump}", options)
|
360
381
|
end
|
361
382
|
}
|
362
383
|
}
|
data/test/config/deploy.rb
CHANGED
@@ -20,25 +20,115 @@ role :db, "192.168.33.10", :primary => true
|
|
20
20
|
$LOAD_PATH.push(File.expand_path("../../lib", File.dirname(__FILE__)))
|
21
21
|
require "capistrano-rbenv"
|
22
22
|
|
23
|
-
|
23
|
+
task(:test_all) {
|
24
|
+
find_and_execute_task("test_default")
|
25
|
+
find_and_execute_task("test_without_global")
|
26
|
+
}
|
27
|
+
|
28
|
+
namespace(:test_default) {
|
24
29
|
task(:default) {
|
25
|
-
find_and_execute_task("rbenv:setup")
|
26
30
|
methods.grep(/^test_/).each do |m|
|
27
31
|
send(m)
|
28
32
|
end
|
29
|
-
|
33
|
+
}
|
34
|
+
before "test_default", "test_default:setup"
|
35
|
+
after "test_default", "test_default:teardown"
|
36
|
+
|
37
|
+
task(:setup) {
|
38
|
+
find_and_execute_task("rbenv:setup")
|
30
39
|
}
|
31
40
|
|
32
|
-
task(:
|
41
|
+
task(:teardown) {
|
42
|
+
}
|
43
|
+
|
44
|
+
task(:test_rbenv) {
|
33
45
|
run("rbenv --version")
|
34
46
|
}
|
35
47
|
|
36
|
-
|
48
|
+
## standard
|
49
|
+
task(:test_rbenv_exec) {
|
50
|
+
rbenv.exec("ruby --version")
|
51
|
+
}
|
52
|
+
|
53
|
+
task(:test_run_rbenv_exec) {
|
37
54
|
run("rbenv exec ruby --version")
|
38
55
|
}
|
39
56
|
|
40
|
-
|
41
|
-
|
57
|
+
## with path
|
58
|
+
task(:test_rbenv_exec_with_path) {
|
59
|
+
rbenv.exec("ruby -e 'exit(Dir.pwd==%{/}?0:1)'", :path => "/")
|
60
|
+
}
|
61
|
+
|
62
|
+
# task(:test_rbenv_exec_ruby_via_sudo_with_path) {
|
63
|
+
# # capistrano does not provide safer way to invoke multiple commands via sudo.
|
64
|
+
# rbenv.exec("ruby -e 'exit(Dir.pwd==%{/}&&Process.uid==0?0:1'", :path => "/", :via => :sudo )
|
65
|
+
# }
|
66
|
+
|
67
|
+
## via sudo
|
68
|
+
task(:test_rbenv_exec_via_sudo) {
|
69
|
+
rbenv.exec("ruby -e 'exit(Process.uid==0?0:1)'", :via => :sudo)
|
70
|
+
}
|
71
|
+
|
72
|
+
task(:test_run_sudo_rbenv_exec) {
|
73
|
+
# we may not be able to invoke rbenv since sudo may reset $PATH.
|
74
|
+
# if you prefer to invoke rbenv via sudo, call it with absolute path.
|
75
|
+
# run("#{sudo} rbenv exec ruby -e 'exit(Process.uid==0?0:1)'")
|
76
|
+
run("#{sudo} #{rbenv_cmd} exec ruby -e 'exit(Process.uid==0?0:1)'")
|
77
|
+
}
|
78
|
+
|
79
|
+
task(:test_sudo_rbenv_exec) {
|
80
|
+
sudo("#{rbenv_cmd} exec ruby -e 'exit(Process.uid==0?0:1)'")
|
81
|
+
}
|
82
|
+
|
83
|
+
## bundler
|
84
|
+
task(:test_run_bundle) {
|
85
|
+
run("#{bundle_cmd} version")
|
86
|
+
}
|
87
|
+
|
88
|
+
task(:test_run_sudo_bundle) {
|
89
|
+
run("#{sudo} #{bundle_cmd} version")
|
90
|
+
}
|
91
|
+
|
92
|
+
task(:test_sudo_bundle) {
|
93
|
+
sudo("#{bundle_cmd} version")
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
namespace(:test_without_global) {
|
98
|
+
task(:default) {
|
99
|
+
methods.grep(/^test_/).each do |m|
|
100
|
+
send(m)
|
101
|
+
end
|
102
|
+
}
|
103
|
+
before "test_without_global", "test_without_global:setup"
|
104
|
+
after "test_without_global", "test_without_global:teardown"
|
105
|
+
|
106
|
+
task(:setup) {
|
107
|
+
version_file = File.join(rbenv_path, "version")
|
108
|
+
run("mv -f #{version_file} #{version_file}.orig")
|
109
|
+
set(:rbenv_setup_global_version, false)
|
110
|
+
find_and_execute_task("rbenv:setup")
|
111
|
+
run("test \! -f #{version_file.dump}")
|
112
|
+
}
|
113
|
+
|
114
|
+
task(:teardown) {
|
115
|
+
version_file = File.join(rbenv_path, "version")
|
116
|
+
run("mv -f #{version_file}.orig #{version_file}")
|
117
|
+
}
|
118
|
+
|
119
|
+
## standard
|
120
|
+
task(:test_rbenv_exec_ruby) {
|
121
|
+
rbenv.exec("ruby --version")
|
122
|
+
}
|
123
|
+
|
124
|
+
## with path
|
125
|
+
task(:test_rbenv_exec_ruby_with_path) {
|
126
|
+
rbenv.exec("ruby -e 'exit(Dir.pwd==%{/}?0:1)'", :path => "/")
|
127
|
+
}
|
128
|
+
|
129
|
+
## via sudo
|
130
|
+
task(:test_rbenv_exec_ruby_via_sudo) {
|
131
|
+
rbenv.exec("ruby -e 'exit(Process.uid==0?0:1)'", :via => :sudo)
|
42
132
|
}
|
43
133
|
}
|
44
134
|
|
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.
|
4
|
+
version: 1.0.0rc2
|
5
5
|
prerelease: 5
|
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-
|
12
|
+
date: 2013-03-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|