poise-ruby 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.kitchen.travis.yml +9 -0
  4. data/.kitchen.yml +9 -0
  5. data/.travis.yml +20 -0
  6. data/.yardopts +7 -0
  7. data/Berksfile +28 -0
  8. data/Gemfile +33 -0
  9. data/LICENSE +201 -0
  10. data/README.md +290 -0
  11. data/Rakefile +17 -0
  12. data/chef/attributes/default.rb +23 -0
  13. data/chef/recipes/default.rb +19 -0
  14. data/lib/poise_ruby.rb +24 -0
  15. data/lib/poise_ruby/cheftie.rb +18 -0
  16. data/lib/poise_ruby/error.rb +21 -0
  17. data/lib/poise_ruby/resources.rb +29 -0
  18. data/lib/poise_ruby/resources/bundle_install.rb +221 -0
  19. data/lib/poise_ruby/resources/ruby_execute.rb +91 -0
  20. data/lib/poise_ruby/resources/ruby_gem.rb +118 -0
  21. data/lib/poise_ruby/resources/ruby_runtime.rb +87 -0
  22. data/lib/poise_ruby/ruby_command_mixin.rb +59 -0
  23. data/lib/poise_ruby/ruby_providers.rb +32 -0
  24. data/lib/poise_ruby/ruby_providers/base.rb +116 -0
  25. data/lib/poise_ruby/ruby_providers/chef.rb +53 -0
  26. data/lib/poise_ruby/ruby_providers/scl.rb +77 -0
  27. data/lib/poise_ruby/ruby_providers/system.rb +115 -0
  28. data/lib/poise_ruby/version.rb +20 -0
  29. data/poise-ruby.gemspec +41 -0
  30. data/test/cookbooks/poise-ruby_test/metadata.rb +18 -0
  31. data/test/cookbooks/poise-ruby_test/recipes/bundle_install.rb +102 -0
  32. data/test/cookbooks/poise-ruby_test/recipes/default.rb +85 -0
  33. data/test/gemfiles/chef-12.gemfile +19 -0
  34. data/test/gemfiles/master.gemfile +23 -0
  35. data/test/integration/default/serverspec/bundle_install_spec.rb +73 -0
  36. data/test/integration/default/serverspec/default_spec.rb +46 -0
  37. data/test/spec/resources/bundle_install_spec.rb +306 -0
  38. data/test/spec/resources/ruby_execute_spec.rb +78 -0
  39. data/test/spec/ruby_command_mixin_spec.rb +34 -0
  40. data/test/spec/spec_helper.rb +18 -0
  41. metadata +155 -0
@@ -0,0 +1,77 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/resource'
18
+ require 'poise_languages'
19
+
20
+ require 'poise_ruby/ruby_providers/base'
21
+
22
+
23
+ module PoiseRuby
24
+ module RubyProviders
25
+ class Scl < Base
26
+ include PoiseLanguages::Scl::Mixin
27
+ provides(:scl)
28
+ scl_package('2.2.2', 'rh-ruby22', {
29
+ ['redhat', 'centos'] => {
30
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-ruby22/epel-7-x86_64/download/rhscl-rh-ruby22-epel-7-x86_64.noarch.rpm',
31
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/rh-ruby22/epel-6-x86_64/download/rhscl-rh-ruby22-epel-6-x86_64.noarch.rpm',
32
+ },
33
+ })
34
+ scl_package('2.0.0', 'ruby200', {
35
+ ['redhat', 'centos'] => {
36
+ # On CentOS 7, the system package is Ruby 2.0.0 and is newer than the SCL build.
37
+ #'~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby200/epel-7-x86_64/download/rhscl-ruby200-epel-7-x86_64.noarch.rpm',
38
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby200/epel-6-x86_64/download/rhscl-ruby200-epel-6-x86_64.noarch.rpm',
39
+ },
40
+ 'fedora' => {
41
+ '~> 21.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby200/fedora-21-x86_64/download/rhscl-ruby200-fedora-21-x86_64.noarch.rpm',
42
+ '~> 20.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby200/fedora-20-x86_64/download/rhscl-ruby200-fedora-20-x86_64.noarch.rpm',
43
+ },
44
+ })
45
+ scl_package('1.9.3', 'ruby193', {
46
+ ['redhat', 'centos'] => {
47
+ '~> 7.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby193/epel-7-x86_64/download/rhscl-ruby193-epel-7-x86_64.noarch.rpm',
48
+ '~> 6.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby193/epel-6-x86_64/download/rhscl-ruby193-epel-6-x86_64.noarch.rpm',
49
+ },
50
+ 'fedora' => {
51
+ '~> 21.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby193/fedora-21-x86_64/download/rhscl-ruby193-fedora-21-x86_64.noarch.rpm',
52
+ '~> 20.0' => 'https://www.softwarecollections.org/en/scls/rhscl/ruby193/fedora-20-x86_64/download/rhscl-ruby193-fedora-20-x86_64.noarch.rpm',
53
+ },
54
+ })
55
+
56
+ def ruby_binary
57
+ ::File.join(scl_folder, 'root', 'usr', 'bin', 'ruby')
58
+ end
59
+
60
+ def ruby_environment
61
+ scl_environment
62
+ end
63
+
64
+ private
65
+
66
+ def install_ruby
67
+ install_scl_package
68
+ end
69
+
70
+ def uninstall_ruby
71
+ uninstall_scl_package
72
+ end
73
+
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,115 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'chef/resource'
18
+ require 'poise_languages'
19
+
20
+ require 'poise_ruby/error'
21
+ require 'poise_ruby/ruby_providers/base'
22
+
23
+
24
+ module PoiseRuby
25
+ module RubyProviders
26
+ class System < Base
27
+ include PoiseLanguages::System::Mixin
28
+ provides(:system)
29
+ packages('ruby', {
30
+ debian: {
31
+ '8' => %w{ruby2.1},
32
+ '7' => %w{ruby1.9.3 ruby1.9.1 ruby1.8},
33
+ # Debian 6 has a ruby1.9.1 package that installs 1.9.2, ignoring it for now.
34
+ '6' => %w{ruby1.8},
35
+ },
36
+ ubuntu: {
37
+ '14.04' => %w{ruby2.0 ruby1.9.3},
38
+ '12.04' => %w{ruby1.9.3 ruby1.8},
39
+ '10.04' => %w{ruby1.9.1 ruby1.8},
40
+ },
41
+ rhel: {default: %w{ruby}},
42
+ centos: {default: %w{ruby}},
43
+ fedora: {default: %w{ruby}},
44
+ # Amazon Linux does actually have packages ruby18, ruby19, ruby20, ruby21.
45
+ # Ignoring for now because wooooo non-standard formatting.
46
+ amazon: {default: %w{ruby}},
47
+ })
48
+
49
+ def self.default_inversion_options(node, resource)
50
+ super.merge({
51
+ # Install a separate rubygems package? Only needed for 1.8.
52
+ rubygems_package: node['platform_family'] == 'rhel' && node['platform_version'].start_with?('6'),
53
+ })
54
+ end
55
+
56
+ # Output value for the Python binary we are installing. Seems to match
57
+ # package name on all platforms I've checked.
58
+ def ruby_binary
59
+ ::File.join('', 'usr', 'bin', system_package_name)
60
+ end
61
+
62
+ private
63
+
64
+ def install_ruby
65
+ install_system_packages
66
+ install_rubygems_package if options['rubygems_package']
67
+ end
68
+
69
+ def uninstall_ruby
70
+ uninstall_system_packages
71
+ end
72
+
73
+ # Ubuntu has no ruby1.9.3-dev package.
74
+ def system_dev_package_overrides
75
+ super.tap do |overrides|
76
+ # WTF Ubuntu, seriously.
77
+ overrides['ruby1.9.3'] = 'ruby1.9.1-dev' if node.platform_family?('debian')
78
+ end
79
+ end
80
+
81
+ # Install the configured rubygems package.
82
+ def install_rubygems_package
83
+ package (options['rubygems_package'].is_a?(String) ? options['rubygems_package'] : 'rubygems')
84
+ end
85
+
86
+ def system_package_candidates(version)
87
+ [].tap do |names|
88
+ # Might as well try it.
89
+ names << "ruby#{version}" if version && !['', '1', '2'].include?(version)
90
+ # On debian, 1.9.1 and 1.9.3 have special packages.
91
+ if match = version.match(/^(\d+\.\d+\.\d+)/)
92
+ names << "ruby#{match[1]}"
93
+ end
94
+ # Normal debian package like ruby2.0.
95
+ if match = version.match(/^(\d+\.\d+)/)
96
+ names << "ruby#{match[1]}"
97
+ end
98
+ # Aliases for ruby1 and ruby2
99
+ if version == '2' || version == ''
100
+ # 2.3 is on there for future proofing. Well, at least giving me a
101
+ # buffer zone.
102
+ names.concat(%w{ruby2.3 ruby2.2 ruby2.1 ruby2.0})
103
+ end
104
+ if version == '1' || version == ''
105
+ names.concat(%w{ruby1.9.3 ruby1.9 ruby1.8})
106
+ end
107
+ # For RHEL and friends.
108
+ names << 'ruby'
109
+ names.uniq!
110
+ end
111
+ end
112
+
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+
18
+ module PoiseRuby
19
+ VERSION = '2.0.0'
20
+ end
@@ -0,0 +1,41 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ lib = File.expand_path('../lib', __FILE__)
18
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
19
+ require 'poise_ruby/version'
20
+
21
+ Gem::Specification.new do |spec|
22
+ spec.name = 'poise-ruby'
23
+ spec.version = PoiseRuby::VERSION
24
+ spec.authors = ['Noah Kantrowitz']
25
+ spec.email = %w{noah@coderanger.net}
26
+ spec.description = "A Chef cookbook for managing Ruby installations."
27
+ spec.summary = spec.description
28
+ spec.homepage = 'https://github.com/poise/poise-ruby'
29
+ spec.license = 'Apache 2.0'
30
+
31
+ spec.files = `git ls-files`.split($/)
32
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
33
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
+ spec.require_paths = %w{lib}
35
+
36
+ spec.add_dependency 'halite', '~> 1.0'
37
+ spec.add_dependency 'poise', '~> 2.0'
38
+ spec.add_dependency 'poise-languages', '~> 1.0.pre'
39
+
40
+ spec.add_development_dependency 'poise-boiler', '~> 1.0'
41
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ name 'poise-ruby_test'
18
+ depends 'poise-ruby'
@@ -0,0 +1,102 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ ruby_runtime 'bundle_install test' do
18
+ version ''
19
+ provider :system
20
+ end
21
+
22
+ directory '/opt/bundle1'
23
+
24
+ file '/opt/bundle1/Gemfile' do
25
+ content <<-EOH
26
+ source 'https://rubygems.org/'
27
+ gem 'rake'
28
+ EOH
29
+ end
30
+
31
+ bundle_install '/opt/bundle1/Gemfile'
32
+
33
+ # Nuke it if needed, tests for notifications require starting from scratch
34
+ execute 'rm -rf /opt/bundle2' if File.exists?('/opt/bundle2')
35
+
36
+ directory '/opt/bundle2'
37
+
38
+ file '/opt/bundle2/Gemfile' do
39
+ content <<-EOH
40
+ source 'https://rubygems.org/'
41
+ gem 'rake'
42
+ EOH
43
+ end
44
+
45
+ file '/opt/bundle2/Gemfile.lock' do
46
+ content <<-EOH
47
+ GEM
48
+ remote: https://rubygems.org/
49
+ specs:
50
+ rake (10.4.2)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ rake
57
+ EOH
58
+ end
59
+
60
+ file '/opt/bundle2/sentinel1' do
61
+ action :nothing
62
+ content ''
63
+ end
64
+
65
+ bundle_install '/opt/bundle2/Gemfile' do
66
+ deployment true
67
+ binstubs true
68
+ notifies :create, 'file[/opt/bundle2/sentinel1]', :immediately
69
+ end
70
+
71
+ file '/opt/bundle2/sentinel2' do
72
+ action :nothing
73
+ content ''
74
+ end
75
+
76
+ bundle_install '/opt/bundle2/Gemfile again' do
77
+ path '/opt/bundle2/Gemfile'
78
+ deployment true
79
+ binstubs true
80
+ notifies :create, 'file[/opt/bundle2/sentinel2]', :immediately
81
+ end
82
+
83
+ if platform_family?('rhel')
84
+ ruby_runtime 'bundle_install test scl' do
85
+ version ''
86
+ provider :scl
87
+ end
88
+
89
+ directory '/opt/bundle3'
90
+
91
+ file '/opt/bundle3/Gemfile' do
92
+ content <<-EOH
93
+ source 'https://rubygems.org/'
94
+ gem 'rake'
95
+ EOH
96
+ end
97
+
98
+ bundle_install '/opt/bundle3/Gemfile' do
99
+ ruby 'bundle_install test scl'
100
+ binstubs true
101
+ end
102
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ # Install lsb-release because Debian 6 doesn't by default and serverspec requires it
18
+ package 'lsb-release' if platform?('debian') && node['platform_version'].start_with?('6')
19
+
20
+ ruby_runtime 'chef' do
21
+ provider :chef
22
+ end
23
+
24
+ ruby_runtime 'any' do
25
+ version ''
26
+ provider :system
27
+ end
28
+
29
+ file '/root/poise_ruby_test.rb' do
30
+ user 'root'
31
+ group 'root'
32
+ mode '644'
33
+ content <<-EOH
34
+ File.open(ARGV[0], 'w') do |f|
35
+ f.write(RUBY_VERSION)
36
+ end
37
+ EOH
38
+ end
39
+
40
+ ruby_execute '/root/poise_ruby_test.rb /root/one'
41
+
42
+ ruby_execute '/root/poise_ruby_test.rb /root/two' do
43
+ ruby 'chef'
44
+ end
45
+
46
+ ruby_gem 'rack' do
47
+ version '1.6.0'
48
+ end
49
+
50
+ file '/root/poise_ruby_test2.rb' do
51
+ user 'root'
52
+ group 'root'
53
+ mode '644'
54
+ content <<-EOH
55
+ require 'rubygems'
56
+ require 'rack'
57
+ File.open(ARGV[0], 'w') do |f|
58
+ f.write(Rack.release)
59
+ end
60
+ EOH
61
+ end
62
+
63
+ ruby_execute '/root/poise_ruby_test2.rb /root/three'
64
+
65
+ if platform_family?('rhel')
66
+ file '/root/scl'
67
+
68
+ ruby_runtime 'scl' do
69
+ version '2'
70
+ provider :scl
71
+ end
72
+
73
+ ruby_execute '/root/poise_ruby_test.rb /root/four' do
74
+ ruby 'scl'
75
+ end
76
+
77
+ ruby_gem 'rack' do
78
+ version '1.6.0'
79
+ ruby 'scl'
80
+ end
81
+
82
+ ruby_execute '/root/poise_ruby_test2.rb /root/five' do
83
+ ruby 'scl'
84
+ end
85
+ end