Upgrade nodejs cookbook from 7.3 to 11.0
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
property :version, String, default: '24.15.0'
|
||||
property :prefix_url, String, default: 'https://nodejs.org/dist/'
|
||||
@@ -0,0 +1,146 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :nodejs_install
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_nodejs'
|
||||
|
||||
property :install_method, String, equal_to: %w(package binary source chocolatey)
|
||||
property :install_repository, [true, false], default: true
|
||||
property :packages, [Array, nil], default: nil
|
||||
property :package_action, [Symbol, String], default: :install
|
||||
property :package_options, [String, nil]
|
||||
property :disable_dnf_module, [true, false], default: true
|
||||
property :source_url, [String, nil]
|
||||
property :source_checksum, [String, nil], default: '729de494dd2872e5a3a6c32a1cd156a5413d4aca2772b2d873ee86bb5531bcd9'
|
||||
property :binary_url, [String, nil]
|
||||
property :binary_checksums, Hash,
|
||||
default: {
|
||||
'linux_x64' => '44836872d9aec49f1e6b52a9a922872db9a2b02d235a616a5681b6a85fec8d89',
|
||||
'linux_arm64' => '73afc234d558c24919875f51c2d1ea002a2ada4ea6f83601a383869fefa64eed',
|
||||
}
|
||||
property :append_env_path, [true, false], default: true
|
||||
property :make_threads, [Integer, String, nil], default: nil
|
||||
property :build_packages, [Array, nil], default: nil
|
||||
property :chocolatey_package_name, String, default: 'nodejs-lts'
|
||||
|
||||
default_action :install
|
||||
|
||||
action :install do
|
||||
case requested_install_method
|
||||
when 'package'
|
||||
nodejs_repository 'nodesource' do
|
||||
node_major node_major_from_version(new_resource.version)
|
||||
action :create
|
||||
only_if { new_resource.install_repository }
|
||||
end
|
||||
|
||||
dnf_module 'nodejs' do
|
||||
action :disable
|
||||
only_if { disable_dnf_module? }
|
||||
end
|
||||
|
||||
resolved_packages.each do |pkg|
|
||||
package pkg do
|
||||
action new_resource.package_action.to_sym
|
||||
options new_resource.package_options if new_resource.package_options
|
||||
end
|
||||
end
|
||||
when 'binary'
|
||||
package 'tar' if platform_family?('rhel', 'fedora', 'amazon', 'suse')
|
||||
|
||||
ark 'nodejs-binary' do
|
||||
url nodejs_binary_url(new_resource.version, new_resource.prefix_url, new_resource.binary_url)
|
||||
version new_resource.version
|
||||
checksum nodejs_binary_checksum(new_resource.binary_checksums) unless new_resource.binary_url
|
||||
has_binaries %w(bin/node bin/npm bin/npx)
|
||||
append_env_path new_resource.append_env_path
|
||||
action :install
|
||||
end
|
||||
when 'source'
|
||||
build_essential 'install build tools'
|
||||
|
||||
(new_resource.build_packages || default_build_packages).each do |pkg|
|
||||
if dnf_python_package?(pkg)
|
||||
execute 'install python3 build package' do
|
||||
command 'dnf -y install python3'
|
||||
not_if 'command -v python3'
|
||||
only_if 'command -v dnf'
|
||||
end
|
||||
else
|
||||
package pkg
|
||||
end
|
||||
end
|
||||
|
||||
link '/usr/local/bin/python' do
|
||||
to '/usr/bin/python3'
|
||||
not_if { ::File.exist?('/usr/bin/python') || ::File.exist?('/usr/local/bin/python') }
|
||||
only_if { ::File.exist?('/usr/bin/python3') }
|
||||
end
|
||||
|
||||
ark 'nodejs-source' do
|
||||
url nodejs_source_url(new_resource.version, new_resource.prefix_url, new_resource.source_url)
|
||||
version new_resource.version
|
||||
checksum new_resource.source_checksum if new_resource.source_checksum
|
||||
make_opts ["-j #{new_resource.make_threads || default_make_threads}"]
|
||||
environment(PYTHON: 'python3')
|
||||
action :install_with_make
|
||||
end
|
||||
when 'chocolatey'
|
||||
chocolatey_package new_resource.chocolatey_package_name do
|
||||
version new_resource.version if new_resource.version
|
||||
action :upgrade
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
case requested_install_method
|
||||
when 'package'
|
||||
resolved_packages.each do |pkg|
|
||||
package pkg do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
|
||||
nodejs_repository 'nodesource' do
|
||||
action :remove
|
||||
only_if { new_resource.install_repository }
|
||||
end
|
||||
when 'binary'
|
||||
ark 'nodejs-binary' do
|
||||
action :remove
|
||||
end
|
||||
when 'source'
|
||||
ark 'nodejs-source' do
|
||||
action :remove
|
||||
end
|
||||
when 'chocolatey'
|
||||
chocolatey_package new_resource.chocolatey_package_name do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include NodeJs::Helper
|
||||
|
||||
def requested_install_method
|
||||
new_resource.install_method || default_install_method
|
||||
end
|
||||
|
||||
def resolved_packages
|
||||
new_resource.packages || default_packages(new_resource.install_repository)
|
||||
end
|
||||
|
||||
def disable_dnf_module?
|
||||
new_resource.disable_dnf_module &&
|
||||
platform_family?('rhel', 'fedora') &&
|
||||
node['platform_version'].to_i >= 8 &&
|
||||
dnf_module_available?('nodejs')
|
||||
end
|
||||
|
||||
def dnf_module_available?(module_name)
|
||||
shell_out!("dnf -q module list #{module_name}", returns: [0, 1]).stdout.match?(/^#{Regexp.escape(module_name)}\s/m)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :nodejs_npm_install
|
||||
unified_mode true
|
||||
|
||||
use '_partial/_nodejs'
|
||||
|
||||
property :install_method, String, equal_to: %w(embedded source), default: 'embedded'
|
||||
property :install_node, [true, false], default: true
|
||||
property :node_install_method, String, equal_to: %w(package binary source chocolatey), default: 'package'
|
||||
property :npm_version, String, default: 'latest'
|
||||
property :npm_url, [String, nil]
|
||||
property :npm_checksum, [String, nil]
|
||||
property :make_threads, [Integer, String, nil], default: nil
|
||||
|
||||
default_action :install
|
||||
|
||||
action :install do
|
||||
nodejs_install 'nodejs for npm' do
|
||||
install_method new_resource.node_install_method
|
||||
version new_resource.version
|
||||
prefix_url new_resource.prefix_url
|
||||
action :install
|
||||
only_if { new_resource.install_node }
|
||||
end
|
||||
|
||||
ark 'npm' do
|
||||
url lazy { npm_dist(new_resource.npm_version, new_resource.npm_url)['url'] }
|
||||
checksum new_resource.npm_checksum if new_resource.npm_checksum
|
||||
version lazy { npm_dist(new_resource.npm_version, new_resource.npm_url)['version'] || new_resource.npm_version }
|
||||
make_opts ["-j #{new_resource.make_threads || default_make_threads}"]
|
||||
action :install_with_make
|
||||
only_if { new_resource.install_method == 'source' }
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
ark 'npm' do
|
||||
action :remove
|
||||
only_if { new_resource.install_method == 'source' }
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include NodeJs::Helper
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :nodejs_npm_packages
|
||||
unified_mode true
|
||||
|
||||
property :packages, Array, default: []
|
||||
|
||||
default_action :install
|
||||
|
||||
action :install do
|
||||
new_resource.packages.each do |pkg|
|
||||
package_properties = normalize_package(pkg)
|
||||
pkg_action = package_properties.delete(:action) || :install
|
||||
pkg_name = package_properties.delete(:package)
|
||||
|
||||
npm_package "nodejs_npm-#{pkg_name}-#{pkg_action}" do
|
||||
package pkg_name
|
||||
package_properties.each do |property_name, property_value|
|
||||
send(property_name, property_value)
|
||||
end
|
||||
action pkg_action.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
new_resource.packages.each do |pkg|
|
||||
package_properties = normalize_package(pkg)
|
||||
pkg_name = package_properties[:package]
|
||||
|
||||
npm_package "nodejs_npm-#{pkg_name}-remove" do
|
||||
package pkg_name
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
def normalize_package(pkg)
|
||||
pkg.each_with_object({}) do |(key, value), memo|
|
||||
property_name = key.to_sym
|
||||
property_name = :package if property_name == :name
|
||||
memo[property_name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,78 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
provides :nodejs_repository
|
||||
unified_mode true
|
||||
|
||||
property :repo_name, String, name_property: true
|
||||
property :node_major, [String, Integer], default: '24'
|
||||
property :apt_uri, String
|
||||
property :apt_distribution, String, default: 'nodistro'
|
||||
property :apt_components, Array, default: ['main']
|
||||
property :apt_key, String, default: 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key'
|
||||
property :apt_keyring, String, default: '/etc/apt/keyrings/nodesource.asc'
|
||||
property :apt_pin_priority, String, default: '600'
|
||||
property :yum_baseurl, String
|
||||
property :yum_gpgkey, String, default: 'https://rpm.nodesource.com/gpgkey/ns-operations-public.key'
|
||||
property :yum_priority, String, default: '9'
|
||||
property :enabled, [true, false], default: true
|
||||
property :gpgcheck, [true, false], default: true
|
||||
|
||||
default_action :create
|
||||
|
||||
action :create do
|
||||
case node['platform_family']
|
||||
when 'debian'
|
||||
package %w(ca-certificates curl gnupg apt-transport-https)
|
||||
|
||||
directory ::File.dirname(new_resource.apt_keyring) do
|
||||
recursive true
|
||||
mode '0755'
|
||||
end
|
||||
|
||||
remote_file new_resource.apt_keyring do
|
||||
source new_resource.apt_key
|
||||
mode '0644'
|
||||
end
|
||||
|
||||
apt_preference new_resource.repo_name do
|
||||
glob '*'
|
||||
pin 'origin deb.nodesource.com'
|
||||
pin_priority new_resource.apt_pin_priority
|
||||
end
|
||||
|
||||
apt_repository new_resource.repo_name do
|
||||
uri lazy { new_resource.apt_uri || "https://deb.nodesource.com/node_#{new_resource.node_major}.x" }
|
||||
components new_resource.apt_components
|
||||
signed_by new_resource.apt_keyring
|
||||
distribution new_resource.apt_distribution
|
||||
end
|
||||
when 'rhel', 'fedora', 'amazon'
|
||||
yum_repository "#{new_resource.repo_name}-nodejs" do
|
||||
description 'nodesource.com nodejs repository'
|
||||
baseurl lazy { new_resource.yum_baseurl || "https://rpm.nodesource.com/pub_#{new_resource.node_major}.x/nodistro/nodejs/$basearch" }
|
||||
gpgkey new_resource.yum_gpgkey
|
||||
priority new_resource.yum_priority
|
||||
enabled new_resource.enabled
|
||||
gpgcheck new_resource.gpgcheck
|
||||
options(module_hotfixes: 1)
|
||||
action :create
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
case node['platform_family']
|
||||
when 'debian'
|
||||
apt_repository new_resource.repo_name do
|
||||
action :remove
|
||||
end
|
||||
|
||||
file new_resource.apt_keyring do
|
||||
action :delete
|
||||
end
|
||||
when 'rhel', 'fedora', 'amazon'
|
||||
yum_repository "#{new_resource.repo_name}-nodejs" do
|
||||
action :remove
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,28 +1,8 @@
|
||||
#
|
||||
# Cookbook:: nodejs
|
||||
# Resource:: npm
|
||||
#
|
||||
# Author:: Sergey Balbeko <sergey@balbeko.com>
|
||||
#
|
||||
# Copyright:: 2012-2017, Sergey Balbeko
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# frozen_string_literal: true
|
||||
|
||||
resource_name :npm_package
|
||||
provides :npm_package
|
||||
unified_mode true
|
||||
|
||||
# backwards compatibility for the old resource name
|
||||
provides :nodejs_npm
|
||||
|
||||
property :package, String, name_property: true
|
||||
@@ -30,7 +10,7 @@ property :version, String
|
||||
property :path, String
|
||||
property :url, String
|
||||
property :json, [String, true, false]
|
||||
property :npm_token, String
|
||||
property :npm_token, String, sensitive: true
|
||||
property :options, Array, default: []
|
||||
property :user, String
|
||||
property :group, String
|
||||
@@ -38,10 +18,7 @@ property :live_stream, [false, true], default: false
|
||||
property :node_env, String
|
||||
property :auto_update, [true, false], default: true
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
@run_context.include_recipe 'nodejs::npm' if node['nodejs']['manage_node']
|
||||
end
|
||||
default_action :install
|
||||
|
||||
action :install do
|
||||
execute "install NPM package #{new_resource.package}" do
|
||||
@@ -51,7 +28,8 @@ action :install do
|
||||
group new_resource.group
|
||||
environment npm_env_vars
|
||||
live_stream new_resource.live_stream
|
||||
not_if { package_installed? && no_auto_update? }
|
||||
sensitive true if new_resource.npm_token
|
||||
not_if { no_auto_update? && package_installed? }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -63,6 +41,20 @@ action :uninstall do
|
||||
group new_resource.group
|
||||
environment npm_env_vars
|
||||
live_stream new_resource.live_stream
|
||||
sensitive true if new_resource.npm_token
|
||||
only_if { package_installed? }
|
||||
end
|
||||
end
|
||||
|
||||
action :remove do
|
||||
execute "uninstall NPM package #{new_resource.package}" do
|
||||
cwd new_resource.path
|
||||
command "npm uninstall #{npm_options}"
|
||||
user new_resource.user
|
||||
group new_resource.group
|
||||
environment npm_env_vars
|
||||
live_stream new_resource.live_stream
|
||||
sensitive true if new_resource.npm_token
|
||||
only_if { package_installed? }
|
||||
end
|
||||
end
|
||||
@@ -75,13 +67,19 @@ action_class do
|
||||
env_vars['HOME'] = ::Dir.home(new_resource.user) if new_resource.user
|
||||
env_vars['USER'] = new_resource.user if new_resource.user
|
||||
env_vars['NPM_TOKEN'] = new_resource.npm_token if new_resource.npm_token
|
||||
env_vars['NODE_ENV'] = new_resource.node_env if new_resource.node_env
|
||||
env_vars['NODE_ENV'] = new_resource.node_env if new_resource.node_env
|
||||
|
||||
env_vars
|
||||
end
|
||||
|
||||
def package_installed?
|
||||
new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path, new_resource.npm_token)
|
||||
return package_json_installed? if new_resource.json == true
|
||||
|
||||
new_resource.package && npm_package_installed?(new_resource.package, new_resource.version, new_resource.path, npm_env_vars)
|
||||
end
|
||||
|
||||
def package_json_installed?
|
||||
new_resource.path && ::File.exist?(::File.join(new_resource.path, 'node_modules'))
|
||||
end
|
||||
|
||||
def no_auto_update?
|
||||
@@ -89,7 +87,7 @@ action_class do
|
||||
end
|
||||
|
||||
def npm_options
|
||||
options = ''
|
||||
options = +''
|
||||
options << ' -global' unless new_resource.path
|
||||
new_resource.options.each do |option|
|
||||
options << " #{option}"
|
||||
|
||||
Reference in New Issue
Block a user