Vendor the external cookbooks
Knife-Zero doesn't include Berkshelf support, so vendoring everything in the repo is convenient again
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
#
|
||||
# Copyright 2015-2017, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/provider'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_ruby/resources/ruby_gem'
|
||||
require 'poise_ruby/resources/ruby_runtime'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module RubyProviders
|
||||
class Base < Chef::Provider
|
||||
include Poise(inversion: :ruby_runtime)
|
||||
|
||||
# Set default inversion options.
|
||||
#
|
||||
# @api private
|
||||
def self.default_inversion_options(node, new_resource)
|
||||
super.merge({
|
||||
bundler_version: new_resource.bundler_version,
|
||||
version: new_resource.version,
|
||||
})
|
||||
end
|
||||
|
||||
# The `install` action for the `ruby_runtime` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
notifying_block do
|
||||
install_ruby
|
||||
install_bundler
|
||||
end
|
||||
end
|
||||
|
||||
# The `uninstall` action for the `ruby_runtime` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_uninstall
|
||||
notifying_block do
|
||||
uninstall_ruby
|
||||
end
|
||||
end
|
||||
|
||||
# The path to the `ruby` binary.
|
||||
#
|
||||
# @abstract
|
||||
# @return [String]
|
||||
def ruby_binary
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
# Output property for environment variables.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
def ruby_environment
|
||||
# No environment variables needed. Rejoice.
|
||||
{}
|
||||
end
|
||||
|
||||
# The path to the `gem` binary. Look relative to the
|
||||
# `ruby` binary for a default implementation.
|
||||
#
|
||||
# @return [String]
|
||||
def gem_binary
|
||||
dir, base = ::File.split(ruby_binary)
|
||||
# If this ruby is called something weird, bail out.
|
||||
raise NotImplementedError unless base.start_with?('ruby')
|
||||
# Allow for names like "ruby2.0" -> "gem2.0".
|
||||
::File.join(dir, base.sub(/^ruby/, 'gem'))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Install the Ruby runtime. Must be implemented by subclass.
|
||||
#
|
||||
# @abstract
|
||||
# @return [void]
|
||||
def install_ruby
|
||||
end
|
||||
|
||||
# Uninstall the Ruby runtime. Must be implemented by subclass.
|
||||
#
|
||||
# @abstract
|
||||
# @return [void]
|
||||
def uninstall_ruby
|
||||
end
|
||||
|
||||
# Install Bundler in to the Ruby runtime.
|
||||
#
|
||||
# @return [void]
|
||||
def install_bundler
|
||||
# Captured because #options conflicts with Chef::Resource::Package#options.
|
||||
bundler_version = options[:bundler_version]
|
||||
return unless bundler_version
|
||||
ruby_gem 'bundler' do
|
||||
action :upgrade if bundler_version == true
|
||||
parent_ruby new_resource
|
||||
version bundler_version if bundler_version.is_a?(String)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,53 @@
|
||||
#
|
||||
# Copyright 2015-2017, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_ruby/error'
|
||||
require 'poise_ruby/ruby_providers/base'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module RubyProviders
|
||||
# Inversion provider for the `ruby_runtime` resource to use whatever Ruby is
|
||||
# currently running, generally Chef's omnibus-d Ruby.
|
||||
#
|
||||
# @since 2.0.0
|
||||
# @provides chef
|
||||
class ChefRuby < Base
|
||||
provides(:chef)
|
||||
|
||||
# The `install` action for the `ruby_runtime` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
# No-op, already installed!
|
||||
end
|
||||
|
||||
# The `uninstall` action for the `ruby_runtime` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_uninstall
|
||||
raise PoiseRuby::Error.new("You cannot uninstall Chef's Ruby.")
|
||||
end
|
||||
|
||||
# The path to the running Ruby binary as determined via RbConfig.
|
||||
#
|
||||
# @return [String]
|
||||
def ruby_binary
|
||||
Gem.ruby
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,77 @@
|
||||
#
|
||||
# Copyright 2015-2017, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'poise_ruby/ruby_providers/base'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module RubyProviders
|
||||
# Inversion provider for the `ruby_runtime` resource to use a fake Ruby,
|
||||
# for use in unit tests.
|
||||
#
|
||||
# @since 2.1.0
|
||||
# @provides dummy
|
||||
class Dummy < Base
|
||||
provides(:dummy)
|
||||
|
||||
def self.default_inversion_options(node, resource)
|
||||
super.merge({
|
||||
# Manual overrides for dummy data.
|
||||
ruby_binary: ::File.join('', 'ruby'),
|
||||
ruby_environment: nil,
|
||||
gem_binary: nil,
|
||||
})
|
||||
end
|
||||
|
||||
# The `install` action for the `ruby_runtime` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
# This space left intentionally blank.
|
||||
end
|
||||
|
||||
# The `uninstall` action for the `ruby_runtime` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_uninstall
|
||||
# This space left intentionally blank.
|
||||
end
|
||||
|
||||
# Path to the non-existent ruby.
|
||||
#
|
||||
# @return [String]
|
||||
def ruby_binary
|
||||
options['ruby_binary']
|
||||
end
|
||||
|
||||
# Environment for the non-existent Ruby.
|
||||
#
|
||||
# @return [String]
|
||||
def ruby_environment
|
||||
options['ruby_environment'] || super
|
||||
end
|
||||
|
||||
# Path to the non-existent gem.
|
||||
#
|
||||
# @return [String]
|
||||
def gem_binary
|
||||
options['gem_binary'] || super
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# Copyright 2015-2017, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/resource'
|
||||
require 'poise_languages'
|
||||
|
||||
require 'poise_ruby/ruby_providers/base'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module RubyProviders
|
||||
class Scl < Base
|
||||
include PoiseLanguages::Scl::Mixin
|
||||
provides(:scl)
|
||||
scl_package('2.4.0', 'rh-ruby24', 'rh-ruby24-ruby-devel')
|
||||
scl_package('2.3.1', 'rh-ruby23', 'rh-ruby23-ruby-devel')
|
||||
scl_package('2.2.2', 'rh-ruby22', 'rh-ruby22-ruby-devel')
|
||||
# On EL7, the system package is Ruby 2.0.0 and is newer than the SCL build.
|
||||
scl_package('2.0.0', 'ruby200', 'ruby200-ruby-devel', '~> 6.0')
|
||||
scl_package('1.9.3', 'ruby193', 'ruby193-ruby-devel')
|
||||
|
||||
def ruby_binary
|
||||
::File.join(scl_folder, 'root', 'usr', 'bin', 'ruby')
|
||||
end
|
||||
|
||||
def ruby_environment
|
||||
scl_environment
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def install_ruby
|
||||
install_scl_package
|
||||
end
|
||||
|
||||
def uninstall_ruby
|
||||
uninstall_scl_package
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
#
|
||||
# Copyright 2015-2017, Noah Kantrowitz
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
require 'chef/resource'
|
||||
require 'poise_languages'
|
||||
|
||||
require 'poise_ruby/error'
|
||||
require 'poise_ruby/ruby_providers/base'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module RubyProviders
|
||||
class System < Base
|
||||
include PoiseLanguages::System::Mixin
|
||||
provides(:system)
|
||||
packages('ruby', {
|
||||
debian: {
|
||||
'8' => %w{ruby2.1},
|
||||
'7' => %w{ruby1.9.3 ruby1.9.1 ruby1.8},
|
||||
# Debian 6 has a ruby1.9.1 package that installs 1.9.2, ignoring it for now.
|
||||
'6' => %w{ruby1.8},
|
||||
},
|
||||
ubuntu: {
|
||||
'16.04' => %w{ruby2.3},
|
||||
'14.04' => %w{ruby2.0 ruby1.9.3},
|
||||
'12.04' => %w{ruby1.9.3 ruby1.8},
|
||||
'10.04' => %w{ruby1.9.1 ruby1.8},
|
||||
},
|
||||
rhel: {default: %w{ruby}},
|
||||
centos: {default: %w{ruby}},
|
||||
fedora: {default: %w{ruby}},
|
||||
# Amazon Linux does actually have packages ruby18, ruby19, ruby20, ruby21.
|
||||
# Ignoring for now because wooooo non-standard formatting.
|
||||
amazon: {default: %w{ruby}},
|
||||
})
|
||||
|
||||
def self.default_inversion_options(node, resource)
|
||||
super.merge({
|
||||
# Install a separate rubygems package? Only needed for 1.8.
|
||||
rubygems_package: node['platform_family'] == 'rhel' && node['platform_version'].start_with?('6'),
|
||||
})
|
||||
end
|
||||
|
||||
# Output value for the Python binary we are installing. Seems to match
|
||||
# package name on all platforms I've checked.
|
||||
def ruby_binary
|
||||
::File.join('', 'usr', 'bin', system_package_name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def install_ruby
|
||||
install_system_packages
|
||||
install_rubygems_package if options['rubygems_package']
|
||||
end
|
||||
|
||||
def uninstall_ruby
|
||||
uninstall_system_packages
|
||||
end
|
||||
|
||||
# Ubuntu has no ruby1.9.3-dev package.
|
||||
def system_dev_package_overrides
|
||||
super.tap do |overrides|
|
||||
# WTF Ubuntu, seriously.
|
||||
overrides['ruby1.9.3'] = 'ruby1.9.1-dev' if node.platform_family?('debian')
|
||||
end
|
||||
end
|
||||
|
||||
# Install the configured rubygems package.
|
||||
def install_rubygems_package
|
||||
package (options['rubygems_package'].is_a?(String) ? options['rubygems_package'] : 'rubygems')
|
||||
end
|
||||
|
||||
def system_package_candidates(version)
|
||||
[].tap do |names|
|
||||
# Might as well try it.
|
||||
names << "ruby#{version}" if version && !['', '1', '2'].include?(version)
|
||||
# On debian, 1.9.1 and 1.9.3 have special packages.
|
||||
if match = version.match(/^(\d+\.\d+\.\d+)/)
|
||||
names << "ruby#{match[1]}"
|
||||
end
|
||||
# Normal debian package like ruby2.0.
|
||||
if match = version.match(/^(\d+\.\d+)/)
|
||||
names << "ruby#{match[1]}"
|
||||
end
|
||||
# Aliases for ruby1 and ruby2
|
||||
if version == '2' || version == ''
|
||||
# 2.3 is on there for future proofing. Well, at least giving me a
|
||||
# buffer zone.
|
||||
names.concat(%w{ruby2.3 ruby2.2 ruby2.1 ruby2.0})
|
||||
end
|
||||
if version == '1' || version == ''
|
||||
names.concat(%w{ruby1.9.3 ruby1.9 ruby1.8})
|
||||
end
|
||||
# For RHEL and friends.
|
||||
names << 'ruby'
|
||||
names.uniq!
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user