Skip to content

Commit

Permalink
Add support for new NodeSource repository (#283)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <[email protected]>
  • Loading branch information
damacus authored Nov 20, 2024
1 parent bd29e64 commit 714e4fa
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 46 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,12 @@ jobs:
matrix:
os:
- "almalinux-9"
- "rockylinux-9"
- "amazonlinux-2023"
- "centos-stream-9"
- "centos-stream-10"
- "debian-11"
- "debian-12"
- "fedora-latest"
- "opensuse-leap-15"
- "rockylinux-8"
- "ubuntu-2204"
- "ubuntu-2404"
suite:
Expand All @@ -43,8 +41,6 @@ jobs:
suite: "source"
- os: "fedora-latest"
suite: "source"
- os: "opensuse-leap-15"
suite: "source"
fail-fast: false

steps:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- Add support for new NodeSource repository (Thanks to @stissot)
- Rework source install packages
- Update SUSE packages

## 10.1.22 - *2024-11-19*

- Update default version to current LTS
Expand Down
2 changes: 1 addition & 1 deletion attributes/packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
default['nodejs']['packages'] = value_for_platform_family(
'debian' => node['nodejs']['install_repo'] ? ['nodejs'] : %w(nodejs npm nodejs-dev),
%w(rhel fedora amazon) => node['nodejs']['install_repo'] ? %w(nodejs nodejs-devel) : %w(nodejs npm nodejs-dev),
'suse' => node['platform_version'].to_i < 42 ? %w(nodejs10 npm10 nodejs10-devel) : %w(nodejs4 npm4 nodejs4-devel),
'suse' => %w(nodejs npm nodejs-devel),
'mac_os_x' => ['node'],
'freebsd' => %w(node npm),
'default' => ['nodejs']
Expand Down
16 changes: 6 additions & 10 deletions attributes/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@
when 'debian'
default['nodejs']['install_repo'] = true
default['nodejs']['repo'] = 'https://deb.nodesource.com/node_20.x'
default['nodejs']['keyserver'] = 'keyserver.ubuntu.com'
default['nodejs']['key'] = '1655a0ab68576280'
when 'rhel', 'amazon'
default['nodejs']['distribution'] = 'nodistro'
default['nodejs']['key'] = 'https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key'
when 'rhel', 'amazon', 'fedora'
default['nodejs']['install_repo'] = true
release_ver = platform?('amazon') ? 7 : node['platform_version'].to_i
default['nodejs']['repo'] = "https://rpm.nodesource.com/pub_20.x/el/#{release_ver}/$basearch"
default['nodejs']['key'] = 'https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL'
when 'fedora'
default['nodejs']['install_repo'] = true
default['nodejs']['repo'] = 'https://rpm.nodesource.com/pub_20.x/el/9/$basearch'
default['nodejs']['key'] = 'https://rpm.nodesource.com/pub/el/NODESOURCE-GPG-SIGNING-KEY-EL'
node_version = platform?('amazon') ? '17.x' : '20.x'
default['nodejs']['repo'] = "https://rpm.nodesource.com/pub_#{node_version}/nodistro/nodejs/$basearch"
default['nodejs']['key'] = 'https://rpm.nodesource.com/gpgkey/ns-operations-public.key'
end
1 change: 1 addition & 0 deletions recipes/nodejs_from_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
if platform_family?('rhel', 'fedora') && node['platform_version'].to_i >= 8 && !node['nodejs']['dnf_module']
dnf_module 'nodejs' do
action :disable
only_if 'dnf module list nodejs'
end
end

Expand Down
18 changes: 3 additions & 15 deletions recipes/nodejs_from_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,13 @@

build_essential 'install build tools'

case node['platform']
case node['platform_family']
when 'rhel', 'fedora', 'amazon'
# The ark resource uses and requires python2 for builds
package %w(openssl-devel python3 tar)
# debian-12 & ubuntu 2204 need python 3
when 'debian'
if node['platform_version'].to_i >= 12
package %w(libssl-dev python3)
else
package %w(libssl-dev python)
end
when 'ubuntu'
if node['platform_version'].to_f >= 22.04
package %w(libssl-dev python3)
else
package %w(libssl-dev python)
end
package %w(libssl-dev python3)
else
package %w(python)
package %w(python3)
end

version = "v#{node['nodejs']['version']}/"
Expand Down
45 changes: 37 additions & 8 deletions recipes/repo.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
case node['platform_family']
when 'debian'
package 'nodejs-apt-transport-https' do
package_name 'apt-transport-https'
# Install necessary packages for downloading and verifying new repository information
package %w(ca-certificates curl gnupg apt-transport-https)

# Create a directory for the new repository's keyring, if it doesn't exist
directory '/etc/apt/keyrings'

# Download the new repository's GPG key and save it in the keyring directory
execute 'add nodejs gpg key' do
command "curl -fsSL #{node['nodejs']['key']} | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg"
not_if { ::File.exist? '/etc/apt/keyrings/nodesource.gpg' }
end

apt_repository 'node.js' do
uri node['nodejs']['repo']
components ['main']
keyserver node['nodejs']['keyserver']
key node['nodejs']['key']
# Prefer nodesource over Ubuntu universe packages by giving a higher priority (default 500)
apt_preference 'nodesource' do
glob '*'
pin 'origin deb.nodesource.com'
pin_priority '600'
end

if Chef::VERSION >= Gem::Version.new('18.3.0')
apt_repository 'nodesource' do
uri node['nodejs']['repo']
components ['main']
options ['signed-by=/etc/apt/keyrings/nodesource.gpg']
distribution node['nodejs']['distribution']
end
else
# Chef Infra < 18.3 doesn't support options attribute, fallback to (deprecated) apt-key method
apt_repository 'nodesource' do
uri node['nodejs']['repo']
components ['main']
key '2F59B5F99B1BE0B4'
keyserver 'keyserver.ubuntu.com'
distribution node['nodejs']['distribution']
end
end

when 'rhel', 'fedora', 'amazon'
yum_repository 'node.js' do
yum_repository 'nodesource-nodejs' do
description 'nodesource.com nodejs repository'
baseurl node['nodejs']['repo']
gpgkey node['nodejs']['key']
priority '9'
options(module_hotfixes: 1)
end
end
18 changes: 11 additions & 7 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe 'default recipe on ubuntu 20.04' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '20.04') }
describe 'default recipe on ubuntu 22.04' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '22.04') }
let(:chef_run) { runner.converge('nodejs::default') }

it 'includes the package install recipes' do
Expand All @@ -14,11 +14,12 @@
end
end

describe 'default recipe on centos 7' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'centos', version: '7') }
describe 'default recipe on centos 8' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'centos', version: '8') }
let(:chef_run) { runner.converge('nodejs::default') }

it 'includes the package install recipes' do
stub_command('dnf module list nodejs').and_return(0)
expect(chef_run).to include_recipe('nodejs::nodejs_from_package')
expect(chef_run).to include_recipe('nodejs::npm_packages')
end
Expand All @@ -28,8 +29,8 @@
end
end

describe 'default recipe on debian 10' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', version: '10') }
describe 'default recipe on debian 12' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'debian', version: '12') }
let(:chef_run) { runner.converge('nodejs::default') }

it 'includes the package install recipes' do
Expand Down Expand Up @@ -58,7 +59,10 @@

describe 'default recipe on fedora' do
let(:runner) { ChefSpec::ServerRunner.new(platform: 'fedora') }
let(:chef_run) { runner.converge('nodejs::default') }
let(:chef_run) do
stub_command('dnf module list nodejs').and_return(0)
runner.converge('nodejs::default')
end

it 'includes the package install recipes' do
expect(chef_run).to include_recipe('nodejs::nodejs_from_package')
Expand Down
12 changes: 12 additions & 0 deletions test/cookbooks/test/recipes/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
user 'random2'
end

directory '/home/random2/.npm' do
owner 'random2'
end

npm_package 'Install the grunt package' do
path '/home/random2'
package 'grunt'
Expand All @@ -71,6 +75,10 @@
user 'random2'
end

directory '/home/random/.npm' do
owner 'random'
end

# Create a package.json file for the test user
template '/home/random/package.json' do
source 'package.json'
Expand All @@ -94,6 +102,10 @@
node_env 'staging' # Test node_env usage
end

directory '/home/random1/.npm' do
owner 'random1'
end

# Create an .npmrc file for the test user
file '/home/random1/.npmrc' do
content '//registry.npmjs.org/:_authToken=${NPM_TOKEN}'
Expand Down

0 comments on commit 714e4fa

Please sign in to comment.