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,144 @@
|
||||
#
|
||||
# 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_languages/static/resource'
|
||||
|
||||
|
||||
module PoiseLanguages
|
||||
module Static
|
||||
# Mixin for language providers to install from static archives.
|
||||
#
|
||||
# @since 1.1.0
|
||||
module Mixin
|
||||
private
|
||||
|
||||
def install_static
|
||||
url = static_url
|
||||
poise_languages_static static_folder do
|
||||
source url
|
||||
strip_components options['strip_components']
|
||||
end
|
||||
end
|
||||
|
||||
def uninstall_static
|
||||
install_static.tap do |r|
|
||||
r.action(:uninstall)
|
||||
end
|
||||
end
|
||||
|
||||
def static_folder
|
||||
options['path'] || ::File.join('', 'opt', "#{self.class.static_name}-#{options['static_version']}")
|
||||
end
|
||||
|
||||
def static_url
|
||||
options['url'] % static_url_variables
|
||||
end
|
||||
|
||||
def static_url_variables
|
||||
{
|
||||
version: options['static_version'],
|
||||
kernel: node['kernel']['name'].downcase,
|
||||
machine: node['kernel']['machine'],
|
||||
machine_label: self.class.static_machine_label_wrapper(node, new_resource),
|
||||
}
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
attr_accessor :static_name
|
||||
attr_accessor :static_versions
|
||||
attr_accessor :static_machines
|
||||
attr_accessor :static_url
|
||||
attr_accessor :static_strip_components
|
||||
attr_accessor :static_retries
|
||||
|
||||
def provides_auto?(node, resource)
|
||||
# Check that the version starts with our project name and the machine
|
||||
# we are on is supported.
|
||||
resource.version.to_s =~ /^#{static_name}(-|$)/ && static_machines.include?(static_machine_label_wrapper(node, resource))
|
||||
end
|
||||
|
||||
# Set some default inversion provider options. Package name can't get
|
||||
# a default value here because that would complicate the handling of
|
||||
# {system_package_candidates}.
|
||||
#
|
||||
# @api private
|
||||
def default_inversion_options(node, resource)
|
||||
super.merge({
|
||||
# Path to install the package. Defaults to /opt/name-version.
|
||||
path: nil,
|
||||
# Number of times to retry failed downloads.
|
||||
retries: static_retries,
|
||||
# Full version number for use in interpolation.
|
||||
static_version: static_version(node, resource),
|
||||
# Value to pass to tar --strip-components.
|
||||
strip_components: static_strip_components,
|
||||
# URL template to download from.
|
||||
url: static_url,
|
||||
})
|
||||
end
|
||||
|
||||
def static_options(name: nil, versions: [], machines: %w{linux-i686 linux-x86_64}, url: nil, strip_components: 1, retries: 5)
|
||||
raise PoiseLanguages::Error.new("Static archive URL is required, on #{self}") unless url
|
||||
self.static_name = name || provides.to_s
|
||||
self.static_versions = versions
|
||||
self.static_machines = Set.new(machines)
|
||||
self.static_url = url
|
||||
self.static_strip_components = strip_components
|
||||
self.static_retries = retries
|
||||
end
|
||||
|
||||
def static_version(node, resource)
|
||||
raw_version = resource.version.to_s.gsub(/^#{static_name}(-|$)/, '')
|
||||
if static_versions.include?(raw_version)
|
||||
raw_version
|
||||
else
|
||||
# Prefix match or just use the given version number if not found.
|
||||
# This allow mild future proofing in some cases.
|
||||
static_versions.find {|v| v.start_with?(raw_version) } || raw_version
|
||||
end
|
||||
end
|
||||
|
||||
def static_machine_label(node, _resource=nil)
|
||||
"#{node['kernel']['name'].downcase}-#{node['kernel']['machine']}"
|
||||
end
|
||||
|
||||
# Wrapper for {#static_machine_label} because I need to add an argument.
|
||||
# This preserves backwards compat.
|
||||
#
|
||||
# @api private
|
||||
def static_machine_label_wrapper(node, resource)
|
||||
args = [node]
|
||||
arity = method(:static_machine_label).arity
|
||||
args << resource if arity > 1 || arity < 0
|
||||
static_machine_label(*args)
|
||||
end
|
||||
|
||||
def included(klass)
|
||||
super
|
||||
klass.extend ClassMethods
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
extend ClassMethods
|
||||
|
||||
Poise::Utils.parameterized_module(self) do |opts|
|
||||
static_options(opts)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,139 @@
|
||||
#
|
||||
# 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 'chef/provider'
|
||||
require 'poise'
|
||||
|
||||
|
||||
module PoiseLanguages
|
||||
module Static
|
||||
# A `poise_languages_static` resource to manage installing a language from
|
||||
# static binary archives. This is an internal implementation detail of
|
||||
# poise-languages.
|
||||
#
|
||||
# @api private
|
||||
# @since 1.1.0
|
||||
# @provides poise_languages_static
|
||||
# @action install
|
||||
# @action uninstall
|
||||
class Resource < Chef::Resource
|
||||
include Poise
|
||||
provides(:poise_languages_static)
|
||||
actions(:install, :uninstall)
|
||||
|
||||
# @!attribute path
|
||||
# Directory to install to.
|
||||
# @return [String]
|
||||
attribute(:path, kind_of: String, name_attribute: true)
|
||||
# @!attribute download_retries
|
||||
# Number of times to retry failed downloads. Defaults to 5.
|
||||
# @return [Integer]
|
||||
attribute(:download_retries, kind_of: Integer, default: 5)
|
||||
# @!attribute source
|
||||
# URL to download from.
|
||||
# @return [String]
|
||||
attribute(:source, kind_of: String, required: true)
|
||||
# @!attribute strip_components
|
||||
# Value to pass to tar --strip-components.
|
||||
# @return [String, Integer, nil]
|
||||
attribute(:strip_components, kind_of: [String, Integer, NilClass], default: 1)
|
||||
|
||||
def cache_path
|
||||
@cache_path ||= ::File.join(Chef::Config[:file_cache_path], source.split(/\//).last)
|
||||
end
|
||||
end
|
||||
|
||||
# The default provider for `poise_languages_static`.
|
||||
#
|
||||
# @api private
|
||||
# @since 1.0
|
||||
# @see Resource
|
||||
# @provides poise_languages_static
|
||||
class Provider < Chef::Provider
|
||||
include Poise
|
||||
provides(:poise_languages_static)
|
||||
|
||||
# The `install` action for the `poise_languages_static` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_install
|
||||
notifying_block do
|
||||
download_archive
|
||||
create_directory
|
||||
# Unpack is handled as a notification from download_archive.
|
||||
end
|
||||
end
|
||||
|
||||
# The `uninstall` action for the `poise_languages_static` resource.
|
||||
#
|
||||
# @return [void]
|
||||
def action_uninstall
|
||||
notifying_block do
|
||||
delete_archive
|
||||
delete_directory
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_directory
|
||||
unpack_resource = unpack_archive
|
||||
directory new_resource.path do
|
||||
user 0
|
||||
group 0
|
||||
mode '755'
|
||||
notifies :unpack, unpack_resource, :immediately
|
||||
end
|
||||
end
|
||||
|
||||
def download_archive
|
||||
unpack_resource = unpack_archive
|
||||
remote_file new_resource.cache_path do
|
||||
source new_resource.source
|
||||
owner 0
|
||||
group 0
|
||||
mode '644'
|
||||
notifies :unpack, unpack_resource, :immediately if ::File.exist?(new_resource.path)
|
||||
retries new_resource.download_retries
|
||||
end
|
||||
end
|
||||
|
||||
def unpack_archive
|
||||
@unpack_archive ||= poise_archive new_resource.cache_path do
|
||||
# Run via notification from #download_archive and #create_directory.
|
||||
action :nothing
|
||||
destination new_resource.path
|
||||
strip_components new_resource.strip_components
|
||||
end
|
||||
end
|
||||
|
||||
def delete_archive
|
||||
file new_resource.cache_path do
|
||||
action :delete
|
||||
end
|
||||
end
|
||||
|
||||
def delete_directory
|
||||
directory new_resource.path do
|
||||
action :delete
|
||||
recursive true
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user