From 379a34c2e2a4b3f20ed5db0c029fddf98ea0e806 Mon Sep 17 00:00:00 2001 From: Matt Larraz Date: Tue, 10 Sep 2024 14:44:29 -0400 Subject: [PATCH 1/6] ARM support for NodeJS --- CHANGELOG.md | 1 + lib/language_pack/helpers/node_installer.rb | 7 +------ lib/language_pack/helpers/nodebin.rb | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da33c7f75..4875c6bd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- Support NodeJS on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1493) ## [v279] - 2024-09-04 diff --git a/lib/language_pack/helpers/node_installer.rb b/lib/language_pack/helpers/node_installer.rb index 16e7eb9d9..7dfecb172 100644 --- a/lib/language_pack/helpers/node_installer.rb +++ b/lib/language_pack/helpers/node_installer.rb @@ -9,7 +9,7 @@ def initialize end def binary_path - node_folder(@version) + File.basename(@url).delete_suffix(".tar.gz") end def install @@ -27,9 +27,4 @@ def install FileUtils.mv("#{dir}/#{node_bin}", ".") end end - - private - def node_folder(version) - "node-v#{version}-linux-x64" - end end diff --git a/lib/language_pack/helpers/nodebin.rb b/lib/language_pack/helpers/nodebin.rb index 1a5c194f9..ac7c13e6d 100644 --- a/lib/language_pack/helpers/nodebin.rb +++ b/lib/language_pack/helpers/nodebin.rb @@ -3,11 +3,12 @@ class LanguagePack::Helpers::Nodebin NODE_VERSION = "20.9.0" YARN_VERSION = "1.22.19" + ARCH = RUBY_PLATFORM.start_with?(/aarch64|arm64/) ? "arm64" : "x64" def self.hardcoded_node_lts { "number" => NODE_VERSION, - "url" => "https://heroku-nodebin.s3.us-east-1.amazonaws.com/node/release/linux-x64/node-v#{NODE_VERSION}-linux-x64.tar.gz" + "url" => "https://nodejs.org/download/release/v#{NODE_VERSION}/node-v#{NODE_VERSION}-linux-#{ARCH}.tar.gz", } end From 003feadef9f7e9bc8681d1fe8646664780f64acb Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 11:52:13 -0500 Subject: [PATCH 2/6] Changelog whitespace --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4875c6bd9..78270aba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog ## [Unreleased] -- Support NodeJS on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1493) +- Support NodeJS on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1493) ## [v279] - 2024-09-04 From 6fbfc8910c2b4df5841780119c31861322e02d12 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 11:54:07 -0500 Subject: [PATCH 3/6] Inject architecture Relying on the format of RUBY_PLATFORM is a little surprising. This allows us to test if we want and reuses the existing architecture logic for consistency. --- lib/language_pack/helpers/node_installer.rb | 4 ++-- lib/language_pack/helpers/nodebin.rb | 10 +++++----- lib/language_pack/ruby.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/language_pack/helpers/node_installer.rb b/lib/language_pack/helpers/node_installer.rb index 7dfecb172..218d1c8b3 100644 --- a/lib/language_pack/helpers/node_installer.rb +++ b/lib/language_pack/helpers/node_installer.rb @@ -1,8 +1,8 @@ class LanguagePack::Helpers::NodeInstaller attr_reader :version - def initialize - nodebin = LanguagePack::Helpers::Nodebin.node_lts + def initialize(arch: ) + nodebin = LanguagePack::Helpers::Nodebin.node_lts(arch: arch) @version = nodebin["number"] @url = nodebin["url"] @fetcher = LanguagePack::Fetcher.new("") diff --git a/lib/language_pack/helpers/nodebin.rb b/lib/language_pack/helpers/nodebin.rb index ac7c13e6d..7632e8366 100644 --- a/lib/language_pack/helpers/nodebin.rb +++ b/lib/language_pack/helpers/nodebin.rb @@ -3,12 +3,12 @@ class LanguagePack::Helpers::Nodebin NODE_VERSION = "20.9.0" YARN_VERSION = "1.22.19" - ARCH = RUBY_PLATFORM.start_with?(/aarch64|arm64/) ? "arm64" : "x64" - def self.hardcoded_node_lts + def self.hardcoded_node_lts(arch: ) + arch = "x64" if arch == "amd64" { "number" => NODE_VERSION, - "url" => "https://nodejs.org/download/release/v#{NODE_VERSION}/node-v#{NODE_VERSION}-linux-#{ARCH}.tar.gz", + "url" => "https://nodejs.org/download/release/v#{NODE_VERSION}/node-v#{NODE_VERSION}-linux-#{arch}.tar.gz", } end @@ -19,8 +19,8 @@ def self.hardcoded_yarn } end - def self.node_lts - hardcoded_node_lts + def self.node_lts(arch: ) + hardcoded_node_lts(arch: arch) end def self.yarn diff --git a/lib/language_pack/ruby.rb b/lib/language_pack/ruby.rb index ced465dc4..65612d7b5 100644 --- a/lib/language_pack/ruby.rb +++ b/lib/language_pack/ruby.rb @@ -34,7 +34,7 @@ def bundler def initialize(*args) super(*args) - @node_installer = LanguagePack::Helpers::NodeInstaller.new + @node_installer = LanguagePack::Helpers::NodeInstaller.new(arch: @arch) @yarn_installer = LanguagePack::Helpers::YarnInstaller.new end From 8ff68bab1d34c3213c4572099bbf9b39d64e181b Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 11:59:57 -0500 Subject: [PATCH 4/6] Update changelog link --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78270aba9..d56a7ae0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] -- Support NodeJS on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1493) +- Support NodeJS on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1499) ## [v279] - 2024-09-04 From 24e390ce736d229aeffbe006b17a689239140536 Mon Sep 17 00:00:00 2001 From: Schneems Date: Tue, 8 Oct 2024 12:08:30 -0500 Subject: [PATCH 5/6] Test node installer with all known architectures --- spec/helpers/node_installer_spec.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/spec/helpers/node_installer_spec.rb b/spec/helpers/node_installer_spec.rb index dff419669..3ba393bb2 100644 --- a/spec/helpers/node_installer_spec.rb +++ b/spec/helpers/node_installer_spec.rb @@ -2,13 +2,15 @@ describe LanguagePack::Helpers::NodeInstaller do describe "#install" do - it "should extract a node binary" do - Dir.mktmpdir do |dir| - Dir.chdir(dir) do - installer = LanguagePack::Helpers::NodeInstaller.new - installer.install + LanguagePack::Base::KNOWN_ARCHITECTURES.each do |arch| + it "should extract a node binary on #{arch}" do + Dir.mktmpdir do |dir| + Dir.chdir(dir) do + installer = LanguagePack::Helpers::NodeInstaller.new(arch: "arm64") + installer.install - expect(File.exist?("node")).to be(true) + expect(File.exist?("node")).to be(true) + end end end end From c3751f8394ddb9b3701afb6b64bd9f0d36a4a3ed Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Tue, 8 Oct 2024 12:54:50 -0500 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d56a7ae0b..4bb7e1106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] -- Support NodeJS on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1499) +- Support Node.js on ARM builds (https://github.com/heroku/heroku-buildpack-ruby/pull/1499) ## [v279] - 2024-09-04