poise-ruby 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.kitchen.travis.yml +9 -0
- data/.kitchen.yml +9 -0
- data/.travis.yml +20 -0
- data/.yardopts +7 -0
- data/Berksfile +28 -0
- data/Gemfile +33 -0
- data/LICENSE +201 -0
- data/README.md +290 -0
- data/Rakefile +17 -0
- data/chef/attributes/default.rb +23 -0
- data/chef/recipes/default.rb +19 -0
- data/lib/poise_ruby.rb +24 -0
- data/lib/poise_ruby/cheftie.rb +18 -0
- data/lib/poise_ruby/error.rb +21 -0
- data/lib/poise_ruby/resources.rb +29 -0
- data/lib/poise_ruby/resources/bundle_install.rb +221 -0
- data/lib/poise_ruby/resources/ruby_execute.rb +91 -0
- data/lib/poise_ruby/resources/ruby_gem.rb +118 -0
- data/lib/poise_ruby/resources/ruby_runtime.rb +87 -0
- data/lib/poise_ruby/ruby_command_mixin.rb +59 -0
- data/lib/poise_ruby/ruby_providers.rb +32 -0
- data/lib/poise_ruby/ruby_providers/base.rb +116 -0
- data/lib/poise_ruby/ruby_providers/chef.rb +53 -0
- data/lib/poise_ruby/ruby_providers/scl.rb +77 -0
- data/lib/poise_ruby/ruby_providers/system.rb +115 -0
- data/lib/poise_ruby/version.rb +20 -0
- data/poise-ruby.gemspec +41 -0
- data/test/cookbooks/poise-ruby_test/metadata.rb +18 -0
- data/test/cookbooks/poise-ruby_test/recipes/bundle_install.rb +102 -0
- data/test/cookbooks/poise-ruby_test/recipes/default.rb +85 -0
- data/test/gemfiles/chef-12.gemfile +19 -0
- data/test/gemfiles/master.gemfile +23 -0
- data/test/integration/default/serverspec/bundle_install_spec.rb +73 -0
- data/test/integration/default/serverspec/default_spec.rb +46 -0
- data/test/spec/resources/bundle_install_spec.rb +306 -0
- data/test/spec/resources/ruby_execute_spec.rb +78 -0
- data/test/spec/ruby_command_mixin_spec.rb +34 -0
- data/test/spec/spec_helper.rb +18 -0
- metadata +155 -0
@@ -0,0 +1,118 @@
|
|
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/provider/package/rubygems'
|
18
|
+
require 'chef/resource/gem_package'
|
19
|
+
require 'poise'
|
20
|
+
|
21
|
+
require 'poise_ruby/ruby_command_mixin'
|
22
|
+
|
23
|
+
|
24
|
+
module PoiseRuby
|
25
|
+
module Resources
|
26
|
+
# (see RubyGem::Resource)
|
27
|
+
# @since 2.0.0
|
28
|
+
module RubyGem
|
29
|
+
# A `ruby_gem` resource to install Ruby gems.
|
30
|
+
#
|
31
|
+
# @provides ruby_gem
|
32
|
+
# @action install
|
33
|
+
# @action upgrade
|
34
|
+
# @action remove
|
35
|
+
# @action purge
|
36
|
+
# @action reconfig
|
37
|
+
# @example
|
38
|
+
# ruby_gem 'rack'
|
39
|
+
class Resource < Chef::Resource::GemPackage
|
40
|
+
include Poise
|
41
|
+
provides(:ruby_gem)
|
42
|
+
include PoiseRuby::RubyCommandMixin
|
43
|
+
|
44
|
+
# @api private
|
45
|
+
def initialize(name, run_context=nil)
|
46
|
+
super
|
47
|
+
@resource_name = :ruby_gem if @resource_name
|
48
|
+
# Remove when all useful versions are using provider resolver.
|
49
|
+
@provider = PoiseRuby::Resources::RubyGem::Provider if @provider
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# The default provider for `ruby_gem`.
|
54
|
+
#
|
55
|
+
# @see Resource
|
56
|
+
# @provides ruby_gem
|
57
|
+
class Provider < Chef::Provider::Package::Rubygems
|
58
|
+
include Poise
|
59
|
+
provides(:ruby_gem)
|
60
|
+
|
61
|
+
def load_current_resource
|
62
|
+
patch_environment { super }
|
63
|
+
end
|
64
|
+
|
65
|
+
def define_resource_requirements
|
66
|
+
patch_environment { super }
|
67
|
+
end
|
68
|
+
|
69
|
+
def action_install
|
70
|
+
patch_environment { super }
|
71
|
+
end
|
72
|
+
|
73
|
+
def action_upgrade
|
74
|
+
patch_environment { super }
|
75
|
+
end
|
76
|
+
|
77
|
+
def action_remove
|
78
|
+
patch_environment { super }
|
79
|
+
end
|
80
|
+
|
81
|
+
def action_purge
|
82
|
+
patch_environment { super }
|
83
|
+
end
|
84
|
+
|
85
|
+
def action_reconfig
|
86
|
+
patch_environment { super }
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def patch_environment(&block)
|
92
|
+
environment_to_add = if new_resource.parent_ruby
|
93
|
+
new_resource.parent_ruby.ruby_environment
|
94
|
+
else
|
95
|
+
{}
|
96
|
+
end
|
97
|
+
|
98
|
+
begin
|
99
|
+
old_vars = environment_to_add.inject({}) do |memo, (key, value)|
|
100
|
+
memo[key] = ENV[key]
|
101
|
+
ENV[key] = value
|
102
|
+
memo
|
103
|
+
end
|
104
|
+
block.call
|
105
|
+
ensure
|
106
|
+
old_vars.each do |key, value|
|
107
|
+
if value.nil?
|
108
|
+
ENV.delete(key)
|
109
|
+
else
|
110
|
+
ENV[key] = value
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,87 @@
|
|
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'
|
19
|
+
|
20
|
+
|
21
|
+
module PoiseRuby
|
22
|
+
module Resources
|
23
|
+
# (see RubyRuntime::Resource)
|
24
|
+
# @since 2.0.0
|
25
|
+
module RubyRuntime
|
26
|
+
# A `ruby_runtime` resource to manage Ruby installations.
|
27
|
+
#
|
28
|
+
# @provides ruby_runtime
|
29
|
+
# @action install
|
30
|
+
# @action uninstall
|
31
|
+
# @example
|
32
|
+
# ruby_runtime '2.1.2'
|
33
|
+
class Resource < Chef::Resource
|
34
|
+
include Poise(inversion: true, container: true)
|
35
|
+
provides(:ruby_runtime)
|
36
|
+
actions(:install, :uninstall)
|
37
|
+
|
38
|
+
# @!attribute version
|
39
|
+
# Version of Ruby to install.
|
40
|
+
# @return [String]
|
41
|
+
attribute(:version, kind_of: String, name_attribute: true)
|
42
|
+
# @!attribute bundler_version
|
43
|
+
# Version of Bundler to install. It set to `true`, the latest
|
44
|
+
# available version will be used. If set to `false`, Bundler will
|
45
|
+
# not be installed.
|
46
|
+
# @note Disabling the Bundler install may result in other resources
|
47
|
+
# being non-functional.
|
48
|
+
# @return [String, Boolean]
|
49
|
+
attribute(:bundler_version, kind_of: [String, TrueClass, FalseClass], default: true)
|
50
|
+
|
51
|
+
# The path to the `ruby` binary for this Ruby installation. This is an
|
52
|
+
# output property.
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
# @example
|
56
|
+
# execute "#{resources('ruby_runtime[2.2.2]').ruby_binary} myapp.rb"
|
57
|
+
def ruby_binary
|
58
|
+
@ruby_binary ||= provider_for_action(:ruby_binary).ruby_binary
|
59
|
+
end
|
60
|
+
|
61
|
+
# The environment variables for this Ruby installation. This is an
|
62
|
+
# output property.
|
63
|
+
#
|
64
|
+
# @return [Hash<String, String>]
|
65
|
+
# @example
|
66
|
+
# execute '/opt/myapp.py' do
|
67
|
+
# environment resources('ruby_runtime[2.2.2]').ruby_environment
|
68
|
+
# end
|
69
|
+
def ruby_environment
|
70
|
+
@ruby_environment ||= provider_for_action(:ruby_environment).ruby_environment
|
71
|
+
end
|
72
|
+
|
73
|
+
# The path to the `gem` binary for this Ruby installation. This is an
|
74
|
+
# output property.
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
# @example
|
78
|
+
# execute "#{resources('ruby_runtime[2.2.2]').gem_binary} install myapp"
|
79
|
+
def gem_binary
|
80
|
+
@gem_binary ||= provider_for_action(:gem_binary).gem_binary
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Providers can be found under lib/poise_ruby/ruby_providers/
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,59 @@
|
|
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 'poise/utils'
|
18
|
+
require 'poise_languages'
|
19
|
+
|
20
|
+
|
21
|
+
module PoiseRuby
|
22
|
+
# Mixin for resources and providers which run Ruby commands.
|
23
|
+
#
|
24
|
+
# @since 1.0.0
|
25
|
+
module RubyCommandMixin
|
26
|
+
include Poise::Utils::ResourceProviderMixin
|
27
|
+
|
28
|
+
module Resource
|
29
|
+
include PoiseLanguages::Command::Mixin::Resource(:ruby)
|
30
|
+
|
31
|
+
# @!attribute gem_binary
|
32
|
+
# Path to the gem binary.
|
33
|
+
# @return [String]
|
34
|
+
attribute(:gem_binary, kind_of: String, default: lazy { default_gem_binary })
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Find the default gem binary. If there is a parent use that, otherwise
|
39
|
+
# use the same logic as {PoiseRuby::RubyProviders::Base#gem_binary}.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
def default_gem_binary
|
43
|
+
if parent_ruby
|
44
|
+
parent_ruby.gem_binary
|
45
|
+
else
|
46
|
+
dir, base = ::File.split(ruby)
|
47
|
+
# If this ruby is called something weird, bail out.
|
48
|
+
raise NotImplementedError unless base.start_with?('ruby')
|
49
|
+
# Allow for names like "ruby2.0" -> "gem2.0".
|
50
|
+
::File.join(dir, base.sub(/^ruby/, 'gem'))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module Provider
|
56
|
+
include PoiseLanguages::Command::Mixin::Provider(:ruby)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,32 @@
|
|
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 'poise_ruby/ruby_providers/chef'
|
18
|
+
require 'poise_ruby/ruby_providers/scl'
|
19
|
+
require 'poise_ruby/ruby_providers/system'
|
20
|
+
|
21
|
+
|
22
|
+
module PoiseRuby
|
23
|
+
# Inversion providers for the ruby_runtime resource.
|
24
|
+
#
|
25
|
+
# @since 2.0.0
|
26
|
+
module RubyProviders
|
27
|
+
Chef::Platform::ProviderPriorityMap.instance.priority(:ruby_runtime, [
|
28
|
+
PoiseRuby::RubyProviders::Scl,
|
29
|
+
PoiseRuby::RubyProviders::System,
|
30
|
+
])
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,116 @@
|
|
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/provider'
|
18
|
+
require 'poise'
|
19
|
+
|
20
|
+
require 'poise_ruby/resources/ruby_runtime'
|
21
|
+
|
22
|
+
|
23
|
+
module PoiseRuby
|
24
|
+
module RubyProviders
|
25
|
+
class Base < Chef::Provider
|
26
|
+
include Poise(inversion: :ruby_runtime)
|
27
|
+
|
28
|
+
# Set default inversion options.
|
29
|
+
#
|
30
|
+
# @api private
|
31
|
+
def self.default_inversion_options(node, new_resource)
|
32
|
+
super.merge({
|
33
|
+
bundler_version: new_resource.bundler_version,
|
34
|
+
version: new_resource.version,
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
# The `install` action for the `ruby_runtime` resource.
|
39
|
+
#
|
40
|
+
# @return [void]
|
41
|
+
def action_install
|
42
|
+
notifying_block do
|
43
|
+
install_ruby
|
44
|
+
install_bundler
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# The `uninstall` action for the `ruby_runtime` resource.
|
49
|
+
#
|
50
|
+
# @return [void]
|
51
|
+
def action_uninstall
|
52
|
+
notifying_block do
|
53
|
+
uninstall_ruby
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# The path to the `ruby` binary.
|
58
|
+
#
|
59
|
+
# @abstract
|
60
|
+
# @return [String]
|
61
|
+
def ruby_binary
|
62
|
+
raise NotImplementedError
|
63
|
+
end
|
64
|
+
|
65
|
+
# Output property for environment variables.
|
66
|
+
#
|
67
|
+
# @return [Hash<String, String>]
|
68
|
+
def ruby_environment
|
69
|
+
# No environment variables needed. Rejoice.
|
70
|
+
{}
|
71
|
+
end
|
72
|
+
|
73
|
+
# The path to the `gem` binary. Look relative to the
|
74
|
+
# `ruby` binary for a default implementation.
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
def gem_binary
|
78
|
+
dir, base = ::File.split(ruby_binary)
|
79
|
+
# If this ruby is called something weird, bail out.
|
80
|
+
raise NotImplementedError unless base.start_with?('ruby')
|
81
|
+
# Allow for names like "ruby2.0" -> "gem2.0".
|
82
|
+
::File.join(dir, base.sub(/^ruby/, 'gem'))
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
# Install the Ruby runtime. Must be implemented by subclass.
|
88
|
+
#
|
89
|
+
# @abstract
|
90
|
+
# @return [void]
|
91
|
+
def install_ruby
|
92
|
+
end
|
93
|
+
|
94
|
+
# Uninstall the Ruby runtime. Must be implemented by subclass.
|
95
|
+
#
|
96
|
+
# @abstract
|
97
|
+
# @return [void]
|
98
|
+
def uninstall_ruby
|
99
|
+
end
|
100
|
+
|
101
|
+
# Install Bundler in to the Ruby runtime.
|
102
|
+
#
|
103
|
+
# @return [void]
|
104
|
+
def install_bundler
|
105
|
+
# Captured because #options conflicts with Chef::Resource::Package#options.
|
106
|
+
bundler_version = options[:bundler_version]
|
107
|
+
return unless bundler_version
|
108
|
+
ruby_gem 'bundler' do
|
109
|
+
action :upgrade if bundler_version == true
|
110
|
+
parent_ruby new_resource
|
111
|
+
version bundler_version if bundler_version.is_a?(String)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,53 @@
|
|
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 'poise_ruby/error'
|
18
|
+
require 'poise_ruby/ruby_providers/base'
|
19
|
+
|
20
|
+
|
21
|
+
module PoiseRuby
|
22
|
+
module RubyProviders
|
23
|
+
# Inversion provider for the `ruby` resource to use whatever Ruby is
|
24
|
+
# currently running, generally Chef's omnibus-d Ruby.
|
25
|
+
#
|
26
|
+
# @since 2.0.0
|
27
|
+
# @provides chef
|
28
|
+
class ChefRuby < Base
|
29
|
+
provides(:chef)
|
30
|
+
|
31
|
+
# The `install` action for the `ruby_runtime` resource.
|
32
|
+
#
|
33
|
+
# @return [void]
|
34
|
+
def action_install
|
35
|
+
# No-op, already installed!
|
36
|
+
end
|
37
|
+
|
38
|
+
# The `uninstall` action for the `ruby_runtime` resource.
|
39
|
+
#
|
40
|
+
# @return [void]
|
41
|
+
def action_uninstall
|
42
|
+
raise PoiseRuby::Error.new("You cannot uninstall Chef's Ruby.")
|
43
|
+
end
|
44
|
+
|
45
|
+
# The path to the running Ruby binary as determined via RbConfig.
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
def ruby_binary
|
49
|
+
Gem.ruby
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|