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,225 @@
|
||||
#
|
||||
# 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/mixin/shell_out'
|
||||
require 'chef/mixin/which'
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_ruby/error'
|
||||
require 'poise_ruby/ruby_command_mixin'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module Resources
|
||||
# (see BundleInstall::Resource)
|
||||
# @since 2.0.0
|
||||
module BundleInstall
|
||||
# A `bundle_install` resource to install a [Bundler](http://bundler.io/)
|
||||
# Gemfile.
|
||||
#
|
||||
# @provides bundle_install
|
||||
# @action install
|
||||
# @action update
|
||||
# @note
|
||||
# This resource is not idempotent itself, it will always run `bundle
|
||||
# install`.
|
||||
# @example
|
||||
# bundle_install '/opt/my_app' do
|
||||
# gem_path '/usr/local/bin/gem'
|
||||
# end
|
||||
class Resource < Chef::Resource
|
||||
include Poise
|
||||
provides(:bundle_install)
|
||||
actions(:install, :update)
|
||||
include PoiseRuby::RubyCommandMixin
|
||||
|
||||
# @!attribute path
|
||||
# Path to the Gemfile or to a directory that contains a Gemfile.
|
||||
# @return [String]
|
||||
attribute(:path, kind_of: String, name_attribute: true)
|
||||
# @!attribute binstubs
|
||||
# Enable binstubs. If set to a string it is the path to generate
|
||||
# stubs in.
|
||||
# @return [Boolean, String]
|
||||
attribute(:binstubs, kind_of: [TrueClass, String])
|
||||
# @!attribute deployment
|
||||
# Enable deployment mode.
|
||||
# @return [Boolean]
|
||||
attribute(:deployment, equal_to: [true, false], default: false)
|
||||
# @!attribute jobs
|
||||
# Number of parallel installations to run.
|
||||
# @return [String, Integer]
|
||||
attribute(:jobs, kind_of: [String, Integer])
|
||||
# @!attribute retry
|
||||
# Number of times to retry failed installations.
|
||||
# @return [String, Integer]
|
||||
attribute(:retry, kind_of: [String, Integer])
|
||||
# @!attribute user
|
||||
# User to run bundler as.
|
||||
# @return [String, Integery, nil]
|
||||
attribute(:user, kind_of: [String, Integer, NilClass])
|
||||
# @!attribute vendor
|
||||
# Enable local vendoring. This maps to the `--path` option in bundler,
|
||||
# but that attribute name is already used.
|
||||
# @return [Boolean, String]
|
||||
attribute(:vendor, kind_of: [TrueClass, String])
|
||||
# @!attribute without
|
||||
# Group or groups to not install.
|
||||
# @return [String, Array<String>]
|
||||
attribute(:without, kind_of: [Array, String])
|
||||
|
||||
# The path to the `bundle` binary for this installation. This is an
|
||||
# output property.
|
||||
#
|
||||
# @return [String]
|
||||
# @example
|
||||
# execute "#{resources('bundle_install[/opt/myapp]').bundler_binary} vendor"
|
||||
def bundler_binary
|
||||
@bundler_binary ||= provider_for_action(:bundler_binary).bundler_binary
|
||||
end
|
||||
|
||||
# The path to the Gemfile for this installation. This is an output
|
||||
# property.
|
||||
#
|
||||
# @return [String]
|
||||
# @example
|
||||
# file resources('bundle_install[/opt/myapp]').gemfile_path do
|
||||
# owner 'root'
|
||||
# end
|
||||
def gemfile_path
|
||||
@gemfile_path ||= provider_for_action(:gemfile_path).gemfile_path
|
||||
end
|
||||
end
|
||||
|
||||
# The default provider for the `bundle_install` resource.
|
||||
#
|
||||
# @see Resource
|
||||
class Provider < Chef::Provider
|
||||
include Poise
|
||||
provides(:bundle_install)
|
||||
include PoiseRuby::RubyCommandMixin
|
||||
|
||||
# Install bundler and the gems in the Gemfile.
|
||||
def action_install
|
||||
run_bundler('install')
|
||||
end
|
||||
|
||||
# Install bundler and update the gems in the Gemfile.
|
||||
def action_update
|
||||
run_bundler('update')
|
||||
end
|
||||
|
||||
# Return the absolute path to the correct bundle binary to run.
|
||||
#
|
||||
# @return [String]
|
||||
def bundler_binary
|
||||
@bundler_binary ||= ::File.join(poise_gem_bindir, 'bundle')
|
||||
end
|
||||
|
||||
# Find the absolute path to the Gemfile. This mirrors bundler's internal
|
||||
# search logic by scanning up to parent folder as needed.
|
||||
#
|
||||
# @return [String]
|
||||
def gemfile_path
|
||||
@gemfile_path ||= begin
|
||||
path = ::File.expand_path(new_resource.path)
|
||||
if ::File.file?(path)
|
||||
# We got a path to a real file, use that.
|
||||
path
|
||||
else
|
||||
# Walk back until path==dirname(path) meaning we are at the root
|
||||
while path != (next_path = ::File.dirname(path))
|
||||
possible_path = ::File.join(path, 'Gemfile')
|
||||
return possible_path if ::File.file?(possible_path)
|
||||
path = next_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Install the gems in the Gemfile.
|
||||
def run_bundler(command)
|
||||
return converge_by "Run bundle #{command}" if whyrun_mode?
|
||||
cmd = ruby_shell_out!(bundler_command(command), environment: {'BUNDLE_GEMFILE' => gemfile_path}, user: new_resource.user)
|
||||
# Look for a line like 'Installing $gemname $version' to know if we did anything.
|
||||
if cmd.stdout.include?('Installing')
|
||||
new_resource.updated_by_last_action(true)
|
||||
end
|
||||
end
|
||||
|
||||
# Parse out the value for Gem.bindir. This is so complicated to minimize
|
||||
# the required configuration on the resource combined with gem having
|
||||
# terrible output formats.
|
||||
#
|
||||
# Renamed from #gem_bindir in 2.3.0 because of a conflict with a method
|
||||
# of the same name in Chef::Mixin::PathSanity (which is pulled in via
|
||||
# ShellOut) added in 13.0.
|
||||
#
|
||||
# @return [String]
|
||||
def poise_gem_bindir
|
||||
cmd = ruby_shell_out!(new_resource.gem_binary, 'environment')
|
||||
# Parse a line like:
|
||||
# - EXECUTABLE DIRECTORY: /usr/local/bin
|
||||
matches = cmd.stdout.scan(/EXECUTABLE DIRECTORY: (.*)$/).first
|
||||
if matches
|
||||
matches.first
|
||||
else
|
||||
raise PoiseRuby::Error.new("Cannot find EXECUTABLE DIRECTORY: #{cmd.stdout}")
|
||||
end
|
||||
end
|
||||
|
||||
# Command line options for the bundle install.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def bundler_options
|
||||
[].tap do |opts|
|
||||
if new_resource.binstubs
|
||||
opts << "--binstubs" + (new_resource.binstubs.is_a?(String) ? "=#{new_resource.binstubs}" : '')
|
||||
end
|
||||
if new_resource.vendor
|
||||
opts << "--path=" + (new_resource.vendor.is_a?(String) ? new_resource.vendor : 'vendor/bundle')
|
||||
end
|
||||
if new_resource.deployment
|
||||
opts << '--deployment'
|
||||
end
|
||||
if new_resource.jobs
|
||||
opts << "--jobs=#{new_resource.jobs}"
|
||||
end
|
||||
if new_resource.retry
|
||||
opts << "--retry=#{new_resource.retry}"
|
||||
end
|
||||
if new_resource.without
|
||||
opts << '--without'
|
||||
opts.insert(-1, *new_resource.without)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Command array to run when installing the Gemfile.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def bundler_command(command)
|
||||
[bundler_binary, command] + bundler_options
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,90 @@
|
||||
#
|
||||
# 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/mash'
|
||||
require 'chef/provider/execute'
|
||||
require 'chef/resource/execute'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_ruby/bundler_mixin'
|
||||
require 'poise_ruby/ruby_command_mixin'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module Resources
|
||||
# (see RubyExecute::Resource)
|
||||
# @since 2.0.0
|
||||
module RubyExecute
|
||||
# A `ruby_execute` resource to run Ruby scripts and commands.
|
||||
#
|
||||
# @provides ruby_execute
|
||||
# @action run
|
||||
# @example
|
||||
# ruby_execute 'myapp.rb' do
|
||||
# user 'myuser'
|
||||
# end
|
||||
class Resource < Chef::Resource::Execute
|
||||
include Poise
|
||||
provides(:ruby_execute)
|
||||
actions(:run)
|
||||
include PoiseRuby::RubyCommandMixin
|
||||
|
||||
# @!attribute parent_bundle
|
||||
# Optional bundle_install resource to run `bundle exec` against.
|
||||
# @return [PoiseRuby::Resources::BundleInstall::Resource]
|
||||
parent_attribute(:bundle, type: :bundle_install, optional: true, auto: false)
|
||||
end
|
||||
|
||||
# The default provider for `ruby_execute`.
|
||||
#
|
||||
# @see Resource
|
||||
# @provides ruby_execute
|
||||
class Provider < Chef::Provider::Execute
|
||||
include PoiseRuby::BundlerMixin
|
||||
provides(:ruby_execute)
|
||||
|
||||
private
|
||||
|
||||
# Command to pass to shell_out.
|
||||
#
|
||||
# @return [String, Array<String>]
|
||||
def command
|
||||
if new_resource.parent_bundle
|
||||
bundle_exec_command(new_resource.command, path: environment['PATH'])
|
||||
else
|
||||
if new_resource.command.is_a?(Array)
|
||||
[new_resource.ruby] + new_resource.command
|
||||
else
|
||||
"#{new_resource.ruby} #{new_resource.command}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Environment variables to pass to shell_out.
|
||||
#
|
||||
# @return [Hash]
|
||||
def environment
|
||||
Mash.new.tap do |environment|
|
||||
environment.update(new_resource.parent_ruby.ruby_environment) if new_resource.parent_ruby
|
||||
environment['BUNDLE_GEMFILE'] = new_resource.parent_bundle.gemfile_path if new_resource.parent_bundle
|
||||
environment.update(new_resource.environment) if new_resource.environment
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,125 @@
|
||||
#
|
||||
# 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/package/rubygems'
|
||||
require 'chef/resource/gem_package'
|
||||
require 'poise'
|
||||
|
||||
require 'poise_ruby/ruby_command_mixin'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module Resources
|
||||
# (see RubyGem::Resource)
|
||||
# @since 2.0.0
|
||||
module RubyGem
|
||||
# A `ruby_gem` resource to install Ruby gems.
|
||||
#
|
||||
# @provides ruby_gem
|
||||
# @action install
|
||||
# @action upgrade
|
||||
# @action remove
|
||||
# @action purge
|
||||
# @action reconfig
|
||||
# @example
|
||||
# ruby_gem 'rack'
|
||||
class Resource < Chef::Resource::GemPackage
|
||||
include Poise
|
||||
provides(:ruby_gem)
|
||||
actions(:install, :upgrade, :remove, :purge, :reconfig)
|
||||
include PoiseRuby::RubyCommandMixin
|
||||
|
||||
# @api private
|
||||
def initialize(name, run_context=nil)
|
||||
super
|
||||
@resource_name = :ruby_gem if @resource_name
|
||||
# Remove when all useful versions are using provider resolver.
|
||||
@provider = PoiseRuby::Resources::RubyGem::Provider if @provider
|
||||
end
|
||||
end
|
||||
|
||||
# The default provider for `ruby_gem`.
|
||||
#
|
||||
# @see Resource
|
||||
# @provides ruby_gem
|
||||
class Provider < Chef::Provider::Package::Rubygems
|
||||
include Poise
|
||||
provides(:ruby_gem)
|
||||
|
||||
def load_current_resource
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
def define_resource_requirements
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
def action_install
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
def action_upgrade
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
def action_remove
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
def action_purge
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
def action_reconfig
|
||||
patch_environment { super }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def patch_environment(&block)
|
||||
environment_to_add = if new_resource.parent_ruby
|
||||
new_resource.parent_ruby.ruby_environment
|
||||
else
|
||||
{}
|
||||
end
|
||||
|
||||
begin
|
||||
if ENV['GEM_HOME'] && !ENV['GEM_HOME'].empty?
|
||||
Chef::Log.warn("[#{new_resource}] $GEM_HOME is set in Chef's environment, this will likely interfere with gem installation")
|
||||
end
|
||||
if ENV['GEM_PATH'] && !ENV['GEM_PATH'].empty?
|
||||
Chef::Log.warn("[#{new_resource}] $GEM_PATH is set in Chef's environment, this will likely interfere with gem installation")
|
||||
end
|
||||
old_vars = environment_to_add.inject({}) do |memo, (key, value)|
|
||||
memo[key] = ENV[key]
|
||||
ENV[key] = value
|
||||
memo
|
||||
end
|
||||
block.call
|
||||
ensure
|
||||
old_vars.each do |key, value|
|
||||
if value.nil?
|
||||
ENV.delete(key)
|
||||
else
|
||||
ENV[key] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,87 @@
|
||||
#
|
||||
# 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'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module Resources
|
||||
# (see RubyRuntime::Resource)
|
||||
# @since 2.0.0
|
||||
module RubyRuntime
|
||||
# A `ruby_runtime` resource to manage Ruby installations.
|
||||
#
|
||||
# @provides ruby_runtime
|
||||
# @action install
|
||||
# @action uninstall
|
||||
# @example
|
||||
# ruby_runtime '2.1.2'
|
||||
class Resource < Chef::Resource
|
||||
include Poise(inversion: true, container: true)
|
||||
provides(:ruby_runtime)
|
||||
actions(:install, :uninstall)
|
||||
|
||||
# @!attribute version
|
||||
# Version of Ruby to install.
|
||||
# @return [String]
|
||||
attribute(:version, kind_of: String, name_attribute: true)
|
||||
# @!attribute bundler_version
|
||||
# Version of Bundler to install. It set to `true`, the latest
|
||||
# available version will be used. If set to `false`, Bundler will
|
||||
# not be installed.
|
||||
# @note Disabling the Bundler install may result in other resources
|
||||
# being non-functional.
|
||||
# @return [String, Boolean]
|
||||
attribute(:bundler_version, kind_of: [String, TrueClass, FalseClass], default: true)
|
||||
|
||||
# The path to the `ruby` binary for this Ruby installation. This is an
|
||||
# output property.
|
||||
#
|
||||
# @return [String]
|
||||
# @example
|
||||
# execute "#{resources('ruby_runtime[2.2.2]').ruby_binary} myapp.rb"
|
||||
def ruby_binary
|
||||
@ruby_binary ||= provider_for_action(:ruby_binary).ruby_binary
|
||||
end
|
||||
|
||||
# The environment variables for this Ruby installation. This is an
|
||||
# output property.
|
||||
#
|
||||
# @return [Hash<String, String>]
|
||||
# @example
|
||||
# execute '/opt/myapp.py' do
|
||||
# environment resources('ruby_runtime[2.2.2]').ruby_environment
|
||||
# end
|
||||
def ruby_environment
|
||||
@ruby_environment ||= provider_for_action(:ruby_environment).ruby_environment
|
||||
end
|
||||
|
||||
# The path to the `gem` binary for this Ruby installation. This is an
|
||||
# output property.
|
||||
#
|
||||
# @return [String]
|
||||
# @example
|
||||
# execute "#{resources('ruby_runtime[2.2.2]').gem_binary} install myapp"
|
||||
def gem_binary
|
||||
@gem_binary ||= provider_for_action(:gem_binary).gem_binary
|
||||
end
|
||||
end
|
||||
|
||||
# Providers can be found under lib/poise_ruby/ruby_providers/
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,213 @@
|
||||
#
|
||||
# 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/mixin/convert_to_class_name'
|
||||
require 'chef/provider'
|
||||
require 'chef/resource'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseRuby
|
||||
module Resources
|
||||
# (see RubyRuntimeTest::Resource)
|
||||
# @since 2.1.0
|
||||
# @api private
|
||||
module RubyRuntimeTest
|
||||
# A `ruby_runtime_test` resource for integration testing of this
|
||||
# cookbook. This is an internal API and can change at any time.
|
||||
#
|
||||
# @provides ruby_runtime_test
|
||||
# @action run
|
||||
class Resource < Chef::Resource
|
||||
include Poise
|
||||
provides(:ruby_runtime_test)
|
||||
actions(:run)
|
||||
|
||||
attribute(:version, kind_of: String, name_attribute: true)
|
||||
attribute(:runtime_provider, kind_of: Symbol)
|
||||
attribute(:path, kind_of: String, default: lazy { default_path })
|
||||
|
||||
def default_path
|
||||
::File.join('', 'root', "ruby_test_#{name}")
|
||||
end
|
||||
end
|
||||
|
||||
# The default provider for `ruby_runtime_test`.
|
||||
#
|
||||
# @see Resource
|
||||
# @provides ruby_runtime_test
|
||||
class Provider < Chef::Provider
|
||||
include Poise
|
||||
provides(:ruby_runtime_test)
|
||||
|
||||
# The `run` action for the `ruby_runtime_test` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_run
|
||||
notifying_block do
|
||||
# Top level directory for this test.
|
||||
directory new_resource.path
|
||||
|
||||
# Install and log the version.
|
||||
ruby_runtime new_resource.name do
|
||||
provider new_resource.runtime_provider if new_resource.runtime_provider
|
||||
version new_resource.version
|
||||
end
|
||||
test_version
|
||||
|
||||
# Test ruby_gem.
|
||||
ruby_gem 'thor remove before' do
|
||||
action :remove
|
||||
package_name 'thor'
|
||||
ruby new_resource.name
|
||||
end
|
||||
test_require('thor', 'thor_before')
|
||||
ruby_gem 'thor' do
|
||||
ruby new_resource.name
|
||||
notifies :create, sentinel_file('thor'), :immediately
|
||||
end
|
||||
test_require('thor', 'thor_mid')
|
||||
ruby_gem 'thor again' do
|
||||
package_name 'thor'
|
||||
ruby new_resource.name
|
||||
notifies :create, sentinel_file('thor2'), :immediately
|
||||
end
|
||||
ruby_gem 'thor remove after' do
|
||||
action :remove
|
||||
package_name 'thor'
|
||||
ruby new_resource.name
|
||||
end
|
||||
test_require('thor', 'thor_after')
|
||||
|
||||
# Use bundler to test something that should always be installed.
|
||||
ruby_gem 'bundler' do
|
||||
ruby new_resource.name
|
||||
notifies :create, sentinel_file('bundler'), :immediately
|
||||
end
|
||||
|
||||
# Create and install a Gemfile.
|
||||
bundle1_path = ::File.join(new_resource.path, 'bundle1')
|
||||
directory bundle1_path
|
||||
file ::File.join(bundle1_path, 'Gemfile') do
|
||||
content <<-EOH
|
||||
source 'https://rubygems.org/'
|
||||
gem 'hashie'
|
||||
gem 'tomlrb', '1.1.0'
|
||||
EOH
|
||||
end
|
||||
bundle1 = bundle_install bundle1_path do
|
||||
ruby new_resource.name
|
||||
end
|
||||
test_require('hashie', bundle: bundle1)
|
||||
test_require('tomlrb', bundle: bundle1)
|
||||
test_require('thor', 'thor_bundle', bundle: bundle1)
|
||||
|
||||
# Test for bundle exec shebang issues.
|
||||
bundle2_path = ::File.join(new_resource.path, 'bundle2')
|
||||
directory bundle2_path
|
||||
file ::File.join(bundle2_path, 'Gemfile') do
|
||||
content <<-EOH
|
||||
source 'https://rubygems.org/'
|
||||
gem 'unicorn'
|
||||
EOH
|
||||
end
|
||||
file ::File.join(bundle2_path, 'Gemfile.lock') do
|
||||
content <<-EOH
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
kgio (2.10.0)
|
||||
rack (1.6.4)
|
||||
raindrops (0.15.0)
|
||||
unicorn (4.9.0)
|
||||
kgio (~> 2.6)
|
||||
rack
|
||||
raindrops (~> 0.7)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
unicorn
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.6
|
||||
EOH
|
||||
end
|
||||
bundle2 = bundle_install bundle2_path do
|
||||
ruby new_resource.name
|
||||
deployment true
|
||||
end
|
||||
# test_require('unicorn', bundle: bundle2)
|
||||
ruby_execute "unicorn --version > #{::File.join(new_resource.path, "unicorn_version")}" do
|
||||
ruby new_resource.name
|
||||
parent_bundle bundle2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sentinel_file(name)
|
||||
file ::File.join(new_resource.path, "sentinel_#{name}") do
|
||||
action :nothing
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def test_version(ruby: new_resource.name)
|
||||
# Only queue up this resource once, the ivar is just for tracking.
|
||||
@ruby_version_test ||= file ::File.join(new_resource.path, 'ruby_version.rb') do
|
||||
user 'root'
|
||||
group 'root'
|
||||
mode '644'
|
||||
content <<-EOH
|
||||
File.new(ARGV[0], 'w').write(RUBY_VERSION)
|
||||
EOH
|
||||
end
|
||||
|
||||
ruby_execute "#{@ruby_version_test.path} #{::File.join(new_resource.path, 'version')}" do
|
||||
ruby ruby if ruby
|
||||
end
|
||||
end
|
||||
|
||||
def test_require(name, path=name, ruby: new_resource.name, bundle: nil, class_name: nil)
|
||||
# Only queue up this resource once, the ivar is just for tracking.
|
||||
@ruby_require_test ||= file ::File.join(new_resource.path, 'require_version.rb') do
|
||||
user 'root'
|
||||
group 'root'
|
||||
mode '644'
|
||||
content <<-EOH
|
||||
require 'rubygems'
|
||||
begin
|
||||
require "\#{ARGV[0]}/version"
|
||||
klass = ARGV[1].split('::').inject(Object) {|memo, name| memo.const_get(name) }
|
||||
File.new(ARGV[2], 'w').write(klass::VERSION)
|
||||
rescue LoadError
|
||||
end
|
||||
EOH
|
||||
end
|
||||
|
||||
class_name ||= Chef::Mixin::ConvertToClassName.convert_to_class_name(name)
|
||||
ruby_execute "#{@ruby_require_test.path} #{name} #{class_name} #{::File.join(new_resource.path, "require_#{path}")}" do
|
||||
ruby ruby if ruby
|
||||
parent_bundle bundle if bundle
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user