rconf 0.6.25 → 0.6.30
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rconf/command.rb +31 -6
- data/lib/rconf/configurators/bundler_configurator.rb +5 -5
- data/lib/rconf/configurators/mercurial_configurator.rb +15 -11
- data/lib/rconf/configurators/passenger_configurator.rb +5 -5
- data/lib/rconf/configurators/ruby_configurator.rb +19 -7
- data/lib/rconf/support/package_installer.rb +20 -4
- data/lib/rconf/version.rb +1 -1
- data/spec/configurators/bundler_configurator_spec.rb +13 -7
- data/spec/configurators/packages_configurator_spec.rb +2 -1
- data/spec/configurators/passenger_configurator_spec.rb +2 -1
- data/spec/configurators/ruby_configurator_spec.rb +24 -4
- metadata +1 -1
data/lib/rconf/command.rb
CHANGED
@@ -18,6 +18,9 @@ module RightConf
|
|
18
18
|
include Singleton
|
19
19
|
include ProgressReporter
|
20
20
|
|
21
|
+
# Builtin RVM commands
|
22
|
+
RVM_COMMANDS = [ 'gem', 'rubygems' ]
|
23
|
+
|
21
24
|
# Execute given command with given arguments
|
22
25
|
#
|
23
26
|
# === Parameters
|
@@ -34,7 +37,7 @@ module RightConf
|
|
34
37
|
end
|
35
38
|
res = Platform.dispatch(command, *args) { :execute }
|
36
39
|
if @verbose
|
37
|
-
msg = (([
|
40
|
+
msg = (([command] + args).compact.join(' ') + ' => ' +
|
38
41
|
res.status.to_s + ': ' + res.output).grey
|
39
42
|
report(msg)
|
40
43
|
end
|
@@ -44,6 +47,27 @@ module RightConf
|
|
44
47
|
res
|
45
48
|
end
|
46
49
|
|
50
|
+
# Execute command in context of activated ruby
|
51
|
+
#
|
52
|
+
# === Parameters
|
53
|
+
# command(String):: Command to run
|
54
|
+
# args(Array):: Command arguments
|
55
|
+
#
|
56
|
+
# === Return
|
57
|
+
# result(CommandResult):: Result of execution (output and exit status)
|
58
|
+
# NOTE: This is the result returned by RVM, not the underlying command
|
59
|
+
# and thus could be successful when the command actually failed...
|
60
|
+
def execute_in_ruby(command, *args)
|
61
|
+
report_fatal('Failed to run in ruby context, no ruby specified') unless @rvm_prefix
|
62
|
+
commands = if RVM_COMMANDS.include?(command)
|
63
|
+
[ @rvm_prefix, command ]
|
64
|
+
else
|
65
|
+
[ @rvm_prefix, 'exec', '--', command ]
|
66
|
+
end
|
67
|
+
args = commands + args
|
68
|
+
execute('rvm', *args)
|
69
|
+
end
|
70
|
+
|
47
71
|
# Execute given command with given arguments using 'sudo'
|
48
72
|
#
|
49
73
|
# === Parameters
|
@@ -66,7 +90,7 @@ module RightConf
|
|
66
90
|
# === Return
|
67
91
|
# result(CommandResult):: Result of execution (output and exit status)
|
68
92
|
def execute_linux(command, *args)
|
69
|
-
out = `#{
|
93
|
+
out = `#{Shellwords.join([command, *args])} 2>&1`
|
70
94
|
result = CommandResult.new(out, $?.exitstatus)
|
71
95
|
end
|
72
96
|
alias :execute_darwin :execute_linux
|
@@ -83,15 +107,16 @@ module RightConf
|
|
83
107
|
raise 'TBD!'
|
84
108
|
end
|
85
109
|
|
86
|
-
# Set
|
110
|
+
# Set ruby to be used by 'execute_in_ruby'
|
87
111
|
#
|
88
112
|
# === Parameters
|
89
|
-
#
|
113
|
+
# ruby(String):: RVM ruby
|
114
|
+
# gemset(String):: RVM gemset
|
90
115
|
#
|
91
116
|
# === Return
|
92
117
|
# true:: Always return true
|
93
|
-
def
|
94
|
-
@
|
118
|
+
def set_ruby(ruby, gemset)
|
119
|
+
@rvm_prefix = "#{ruby}@#{gemset}"
|
95
120
|
true
|
96
121
|
end
|
97
122
|
|
@@ -34,7 +34,7 @@ module RightConf
|
|
34
34
|
# true:: Always return true
|
35
35
|
def run_linux
|
36
36
|
report_check("Checking for bundler #{version}")
|
37
|
-
res = Command.
|
37
|
+
res = Command.execute_in_ruby('bundle', '--version')
|
38
38
|
success = (res.output =~ /#{version}/)
|
39
39
|
report_result(success)
|
40
40
|
install_bundler unless success
|
@@ -43,7 +43,7 @@ module RightConf
|
|
43
43
|
options << "--without=#{exclusions}" unless exclusions.nil?
|
44
44
|
options << "--path #{bundle_path}" unless bundle_path.nil?
|
45
45
|
options << { :abort_on_failure => 'Failed to install gems' }
|
46
|
-
res = Command.
|
46
|
+
res = Command.execute_in_ruby('bundle', *options)
|
47
47
|
report_success
|
48
48
|
true
|
49
49
|
end
|
@@ -67,11 +67,11 @@ module RightConf
|
|
67
67
|
# === Raise
|
68
68
|
# (Exception):: If bundler gem cannot be found or installed
|
69
69
|
def install_bundler
|
70
|
-
res = Command.
|
70
|
+
res = Command.execute_in_ruby('bundle', '--version')
|
71
71
|
exists = res.success? && res.output !~ /exec: bundle: not found/
|
72
72
|
if exists
|
73
73
|
report_check('Uninstalling existing versions of bundler')
|
74
|
-
Command.
|
74
|
+
Command.execute_in_ruby('gem', 'uninstall', 'bundler', '-a', '-x')
|
75
75
|
report_success
|
76
76
|
end
|
77
77
|
report_check("Installing bundler #{version}")
|
@@ -84,7 +84,7 @@ module RightConf
|
|
84
84
|
options = [ 'gem','install' ]
|
85
85
|
options += bundler_file
|
86
86
|
options += [ '--no-ri', '--no-rdoc', { :abort_on_failure => 'Failed to install bundler' } ]
|
87
|
-
res = Command.
|
87
|
+
res = Command.execute_in_ruby(*options)
|
88
88
|
report_success
|
89
89
|
true
|
90
90
|
end
|
@@ -31,7 +31,7 @@ module RightConf
|
|
31
31
|
def run_linux
|
32
32
|
unless mercurial_installed
|
33
33
|
opts = { :report => true }.merge(abort_option('Failed to install Mercurial'))
|
34
|
-
PackageInstaller.install('mercurial', opts)
|
34
|
+
PackageInstaller.install('mercurial', opts) { !mercurial_installed }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -42,17 +42,21 @@ module RightConf
|
|
42
42
|
def run_darwin
|
43
43
|
unless mercurial_installed
|
44
44
|
report_check('Installing Mercurial')
|
45
|
-
tempdir = File.join(ENV['HOME'], '.
|
45
|
+
tempdir = File.join(ENV['HOME'], '.rconf_temp')
|
46
46
|
FileUtils.mkdir_p(tempdir)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
begin
|
48
|
+
Dir.chdir(tempdir) do
|
49
|
+
Command.execute('curl', '-O', '-f', MAC_MERCURIAL_URL,
|
50
|
+
abort_option('Failed to download Mercurial'))
|
51
|
+
Command.execute('unzip', File.basename(MAC_MERCURIAL_URL),
|
52
|
+
abort_option('Failed to unzip Mercurial'))
|
53
|
+
end
|
54
|
+
Dir.chdir(File.join(tempdir, MAC_MERCURIAL_FILE)) do
|
55
|
+
Command.sudo('installer', '-pkg', MAC_MERCURIAL_FILE.gsub('_', '+') + '.mpkg', '-target', '/',
|
56
|
+
abort_option('Failed to install Mercurial'))
|
57
|
+
end
|
58
|
+
ensure
|
59
|
+
FileUtils.rm_rf(tempdir)
|
56
60
|
end
|
57
61
|
report_success
|
58
62
|
end
|
@@ -40,7 +40,7 @@ module RightConf
|
|
40
40
|
def run_linux
|
41
41
|
set_defaults
|
42
42
|
report_check("Checking for passenger gem #{gem_version}")
|
43
|
-
res = Command.
|
43
|
+
res = Command.execute_in_ruby('gem', 'list', 'passenger')
|
44
44
|
success = (res.output =~ /^passenger \(#{gem_version}\)$/)
|
45
45
|
report_result(success)
|
46
46
|
install_gem unless success
|
@@ -112,7 +112,7 @@ module RightConf
|
|
112
112
|
# true:: Always return true
|
113
113
|
def install_gem
|
114
114
|
report_check('Installing passenger gem')
|
115
|
-
Command.
|
115
|
+
Command.execute_in_ruby('gem', 'install', 'passenger', '-v', gem_version,
|
116
116
|
:abort_on_failure => "Failed to install passenger gem version #{gem_version}")
|
117
117
|
report_success
|
118
118
|
end
|
@@ -126,7 +126,7 @@ module RightConf
|
|
126
126
|
# Grrrrr passenger installer expect rake where it's not... HACK
|
127
127
|
ruby_dir = File.dirname(`which ruby`.chomp)
|
128
128
|
FileUtils.cp(`which rake`.chomp, ruby_dir) unless rake_exist = File.exist?(File.join(ruby_dir, 'rake'))
|
129
|
-
Command.
|
129
|
+
Command.execute_in_ruby('passenger-install-nginx-module', '--auto',
|
130
130
|
'--auto-download', '--prefix', install_path,
|
131
131
|
:abort_on_failure => "Failed to install nginx into #{install_path}")
|
132
132
|
FileUtils.mkdir_p(File.join(install_path, 'sites-enabled'))
|
@@ -173,8 +173,8 @@ module RightConf
|
|
173
173
|
# === Return
|
174
174
|
# config(String):: Nginx config
|
175
175
|
def nginx_config
|
176
|
-
ruby_bin = Command.
|
177
|
-
res = Command.
|
176
|
+
ruby_bin = Command.execute_in_ruby('which', 'ruby').output.chomp
|
177
|
+
res = Command.execute_in_ruby('ruby', '-e', "require 'rubygems';puts Gem.source_index.find_name('passenger').detect { |g| g.version.to_s == '#{PASSENGER_GEM_VERSION}' }.full_gem_path",
|
178
178
|
:abort_on_failure => 'Could not find passenger gem to build passenger_root')
|
179
179
|
passenger_root = res.output.chomp
|
180
180
|
report_fatal('Could not find passenger gem') if passenger_root.empty?
|
@@ -36,6 +36,7 @@ module RightConf
|
|
36
36
|
# true:: Always return true
|
37
37
|
def run_linux
|
38
38
|
check_rvm(RVM_VERSION)
|
39
|
+
Command.set_ruby(version, gemset)
|
39
40
|
report_check("Checking whether #{version} is the active ruby")
|
40
41
|
out = Command.execute('rvm', 'list').output
|
41
42
|
if out =~ /^=> #{version.gsub('.', '\\.')}/
|
@@ -47,8 +48,10 @@ module RightConf
|
|
47
48
|
case out
|
48
49
|
when /is not installed\./
|
49
50
|
report_failure
|
50
|
-
report_fatal "Failed to install #{ruby}
|
51
|
-
|
51
|
+
report_fatal "Failed to install #{ruby}" if @tried
|
52
|
+
install_ruby(version)
|
53
|
+
@tried = true
|
54
|
+
Command.execute_in_ruby('gem', 'install', 'rconf') unless gemset
|
52
55
|
run
|
53
56
|
return true
|
54
57
|
when /^Using /
|
@@ -69,7 +72,7 @@ module RightConf
|
|
69
72
|
report_check("Creating gemset #{gemset} for #{version}")
|
70
73
|
Command.execute('rvm', version, 'gemset', 'create', gemset,
|
71
74
|
:abort_on_failure => "Failed to create gemset '#{gemset}'")
|
72
|
-
Command.
|
75
|
+
Command.execute_in_ruby('gem', 'install', 'rconf')
|
73
76
|
report_success
|
74
77
|
end
|
75
78
|
report_check("Switching to gemset #{gemset}")
|
@@ -77,6 +80,16 @@ module RightConf
|
|
77
80
|
:abort_on_failure => "Failed to switch to gemset '#{gemset}'")
|
78
81
|
report_success
|
79
82
|
end
|
83
|
+
report_check("Checking whether rubygems #{rubygems} is installed")
|
84
|
+
res = Command.execute_in_ruby('gem', '--version')
|
85
|
+
if res.success? && res.output.chomp == rubygems
|
86
|
+
report_success
|
87
|
+
else
|
88
|
+
report_failure
|
89
|
+
report_check("Installing rubygems #{rubygems}")
|
90
|
+
Command.execute_in_ruby('rubygems', rubygems, :abort_on_failure => 'Failed to install rubygems')
|
91
|
+
report_success
|
92
|
+
end
|
80
93
|
true
|
81
94
|
end
|
82
95
|
alias :run_darwin :run_linux
|
@@ -95,7 +108,7 @@ module RightConf
|
|
95
108
|
# === Return
|
96
109
|
# true:: Always return true
|
97
110
|
def post_process
|
98
|
-
Command.
|
111
|
+
Command.set_ruby(version, gemset)
|
99
112
|
check_rvmrc
|
100
113
|
true
|
101
114
|
end
|
@@ -142,14 +155,13 @@ module RightConf
|
|
142
155
|
# ruby(String):: Ruby version compatible with rvm
|
143
156
|
#
|
144
157
|
# === Return
|
145
|
-
#
|
158
|
+
# true:: Always return true
|
146
159
|
def install_ruby(ruby)
|
147
160
|
Platform.dispatch(ruby) { :install_ruby_prerequesites }
|
148
161
|
report_check("Installing #{ruby} (this will take a while, please be patient)")
|
149
162
|
Command.execute('rvm', 'install', ruby, :abort_on_failure => 'Failed to install ruby')
|
150
|
-
res = Command.execute('rvm', ruby, 'gem', 'install', 'rconf')
|
151
163
|
report_success
|
152
|
-
|
164
|
+
true
|
153
165
|
end
|
154
166
|
|
155
167
|
# Make sure to install all required linux packages first
|
@@ -24,14 +24,30 @@ module RightConf
|
|
24
24
|
# and display given error message if install fails when set
|
25
25
|
# opts[:report](TrueClass|FalseClass):: Whether to report installation
|
26
26
|
#
|
27
|
+
# === Block
|
28
|
+
# If a block is given it will get called with no argument prior to the
|
29
|
+
# packages being installed. If the block returns true then installation
|
30
|
+
# will proceed otherwise it won't. Use the block to check whether
|
31
|
+
# installation is required or whether the packages are already installed.
|
32
|
+
# If no block is given then installation will always occur.
|
33
|
+
#
|
27
34
|
# === Return
|
28
35
|
# true:: Always return true
|
29
|
-
def install(packages, opts=nil)
|
36
|
+
def install(packages, opts=nil, &install_check)
|
30
37
|
packages = [ packages ].flatten
|
31
38
|
report = opts && opts.delete(:report)
|
32
|
-
|
33
|
-
|
34
|
-
|
39
|
+
must_install = true
|
40
|
+
if install_check
|
41
|
+
report_check("Checking for #{packages.join(', ')}") if report
|
42
|
+
must_install = install_check.call
|
43
|
+
report_result(must_install) if report
|
44
|
+
end
|
45
|
+
if must_install
|
46
|
+
report_check("Installing #{packages.join(', ')}") if report
|
47
|
+
Platform.dispatch(packages, opts) { :install }
|
48
|
+
report_success if report
|
49
|
+
end
|
50
|
+
true
|
35
51
|
end
|
36
52
|
|
37
53
|
protected
|
data/lib/rconf/version.rb
CHANGED
@@ -20,27 +20,33 @@ describe RightConf::BundlerConfigurator do
|
|
20
20
|
before(:each) do
|
21
21
|
lang = RightConf::Language.parse('bundler { version "0" }')
|
22
22
|
@configurator = lang.configurators.first
|
23
|
-
[:report_check, :report_result, :
|
23
|
+
[:report_check, :report_result, :report_success].each do |meth|
|
24
24
|
flexmock(@configurator).should_receive(meth)
|
25
25
|
end
|
26
|
+
flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
|
27
|
+
RightConf::Command.instance.instance_variable_set(:@rvm_prefix, 'r@g')
|
28
|
+
end
|
29
|
+
|
30
|
+
after(:each) do
|
31
|
+
RightConf::Command.instance.instance_variable_set(:@rvm_prefix, nil)
|
26
32
|
end
|
27
33
|
|
28
34
|
it 'should succeed when bundler succeeds' do
|
29
|
-
flexmock(RightConf::Command.instance).should_receive(:
|
35
|
+
flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).once.with(
|
30
36
|
'bundle', '--version').and_return(success_result('0'))
|
31
|
-
flexmock(RightConf::Command.instance).should_receive(:
|
37
|
+
flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).once.with(
|
32
38
|
'bundle','_0_', 'install', {:abort_on_failure=>"Failed to install gems"}).and_return(success_result)
|
33
39
|
@configurator.run_linux
|
34
40
|
end
|
35
41
|
|
36
42
|
it 'should install bunlder if needed' do
|
37
|
-
flexmock(RightConf::Command.instance).should_receive(:
|
43
|
+
flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).twice.with(
|
38
44
|
'bundle', '--version').and_return(success_result('1'))
|
39
|
-
flexmock(RightConf::Command.instance).should_receive(:
|
45
|
+
flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).once.with(
|
40
46
|
'bundle','_0_', 'install', {:abort_on_failure=>"Failed to install gems"}).and_return(success_result)
|
41
|
-
flexmock(RightConf::Command.instance).should_receive(:
|
47
|
+
flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).once.with(
|
42
48
|
'gem', 'uninstall', 'bundler', '-a', '-x').and_return(success_result)
|
43
|
-
flexmock(RightConf::Command.instance).should_receive(:
|
49
|
+
flexmock(RightConf::Command.instance).should_receive(:execute_in_ruby).once.with(
|
44
50
|
'gem', 'install', 'bundler', '-v', '0', '--no-ri', '--no-rdoc',
|
45
51
|
{:abort_on_failure=>"Failed to install bundler"}).once.and_return(success_result)
|
46
52
|
@configurator.run_linux
|
@@ -20,9 +20,10 @@ describe RightConf::PackagesConfigurator do
|
|
20
20
|
before(:each) do
|
21
21
|
lang = RightConf::Language.parse('packages { debian %w(deb1 deb2); centos %w(cent1 cent2); darwin %w(mac1 mac2) }')
|
22
22
|
@configurator = lang.configurators.first
|
23
|
-
[:report_check, :report_result, :
|
23
|
+
[:report_check, :report_result, :report_success].each do |meth|
|
24
24
|
flexmock(@configurator).should_receive(meth)
|
25
25
|
end
|
26
|
+
flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
|
26
27
|
end
|
27
28
|
|
28
29
|
it 'should install packages on Ubuntu' do
|
@@ -16,9 +16,10 @@ describe RightConf::PassengerConfigurator do
|
|
16
16
|
before(:each) do
|
17
17
|
lang = RightConf::Language.parse('passenger {}')
|
18
18
|
@configurator = lang.configurators.first
|
19
|
-
[:report_check, :report_result, :
|
19
|
+
[:report_check, :report_result, :report_success].each do |meth|
|
20
20
|
flexmock(@configurator).should_receive(meth)
|
21
21
|
end
|
22
|
+
flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
|
22
23
|
end
|
23
24
|
|
24
25
|
it 'should set defaults' do
|
@@ -22,9 +22,10 @@ describe RightConf::RubyConfigurator do
|
|
22
22
|
before(:each) do
|
23
23
|
lang = RightConf::Language.parse('ruby { version "0"; rubygems "1" }')
|
24
24
|
@configurator = lang.configurators.first
|
25
|
-
[:report_check, :report_result, :
|
25
|
+
[:report_check, :report_result, :report_success, :report].each do |meth|
|
26
26
|
flexmock(@configurator).should_receive(meth)
|
27
27
|
end
|
28
|
+
flexmock(@configurator).should_receive(:report_fatal).and_return { |*args| raise args.join(' ') }
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'should succeed on linux when rvm succeeds' do
|
@@ -33,7 +34,9 @@ describe RightConf::RubyConfigurator do
|
|
33
34
|
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
34
35
|
'rvm', 'list').and_return(success_result("=> rvm #{RVM_VERSION}"))
|
35
36
|
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
36
|
-
'rvm', 'use', '0').and_return(success_result('Using'))
|
37
|
+
'rvm', 'use', '0').and_return(success_result('Using '))
|
38
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
39
|
+
'rvm', '0@', 'gem', '--version').and_return(success_result('1'))
|
37
40
|
@configurator.run_linux
|
38
41
|
end
|
39
42
|
|
@@ -54,8 +57,25 @@ describe RightConf::RubyConfigurator do
|
|
54
57
|
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
55
58
|
'./install', {:abort_on_failure=>"Failed to install rvm #{RVM_VERSION}"}).and_return(success_result)
|
56
59
|
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
57
|
-
'rvm', 'use', '0').and_return(success_result('Using'))
|
58
|
-
|
60
|
+
'rvm', 'use', '0').and_return(success_result('Using '))
|
61
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
62
|
+
'rvm', '0@', 'gem', '--version').and_return(success_result('1'))
|
63
|
+
flexmock(@configurator).should_receive(:setup_bashrc).once.and_return(true)
|
64
|
+
@configurator.run_linux
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should install rubygems if needed' do
|
68
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
69
|
+
'rvm', '--version').and_return(success_result("rvm #{RVM_VERSION}"))
|
70
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
71
|
+
'rvm', 'list').and_return(success_result("=> rvm #{RVM_VERSION}"))
|
72
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
73
|
+
'rvm', 'use', '0').and_return(success_result('Using '))
|
74
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
75
|
+
'rvm', '0@', 'gem', '--version').and_return(success_result('0'))
|
76
|
+
flexmock(RightConf::Command.instance).should_receive(:execute).once.with(
|
77
|
+
'rvm', '0@', 'rubygems', '1',
|
78
|
+
{:abort_on_failure=>'Failed to install rubygems'}).and_return(success_result)
|
59
79
|
@configurator.run_linux
|
60
80
|
end
|
61
81
|
|