From 39026cd1da6ead1f09a34d0549619dc83651e21f Mon Sep 17 00:00:00 2001 From: Rune Soerensen Date: Mon, 6 May 2024 11:00:53 -0400 Subject: [PATCH 1/5] Add arch in heroku-24 download url --- buildpacks/ruby/buildpack.toml | 3 +++ .../ruby/src/layers/ruby_install_layer.rs | 26 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/buildpacks/ruby/buildpack.toml b/buildpacks/ruby/buildpack.toml index 4871fc40..51b6c1d1 100644 --- a/buildpacks/ruby/buildpack.toml +++ b/buildpacks/ruby/buildpack.toml @@ -17,5 +17,8 @@ id = "heroku-20" [[stacks]] id = "heroku-22" +[[stacks]] +id = "heroku-24" + [metadata.release] image = { repository = "docker.io/heroku/buildpack-ruby" } diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 35f0238d..7cb0580e 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -2,6 +2,7 @@ use commons::output::{ fmt::{self}, section_log::{log_step, log_step_timed, SectionLogger}, }; +use libcnb::data::stack_id; use crate::{RubyBuildpack, RubyBuildpackError}; use commons::gemfile_lock::ResolvedRubyVersion; @@ -130,10 +131,18 @@ fn download_url(stack: &StackId, version: impl std::fmt::Display) -> Result Date: Mon, 6 May 2024 11:09:28 -0400 Subject: [PATCH 2/5] Add changelog entry --- buildpacks/ruby/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buildpacks/ruby/CHANGELOG.md b/buildpacks/ruby/CHANGELOG.md index 17e51171..5da67990 100644 --- a/buildpacks/ruby/CHANGELOG.md +++ b/buildpacks/ruby/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Added support for `heroku-24` / `heroku/builder:24`. ([#280](https://github.com/heroku/buildpacks-ruby/pull/280)) + ## [2.1.3] - 2024-03-18 ### Changed From c626c59b98ca852a18d32157b2189e244ba43271 Mon Sep 17 00:00:00 2001 From: Rune Soerensen Date: Wed, 8 May 2024 09:49:13 -0400 Subject: [PATCH 3/5] Get ruby arch identifier from host arch --- .../ruby/src/layers/ruby_install_layer.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 7cb0580e..6a7d830b 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -12,6 +12,7 @@ use libcnb::data::buildpack::StackId; use libcnb::data::layer_content_metadata::LayerTypes; use libcnb::layer::{ExistingLayerStrategy, Layer, LayerData, LayerResult, LayerResultBuilder}; use serde::{Deserialize, Serialize}; +use std::env::consts; use std::io; use std::path::Path; use tar::Archive; @@ -135,7 +136,7 @@ fn download_url(stack: &StackId, version: impl std::fmt::Display) -> Result Result Result { + match consts::ARCH { + "x86_64" => Ok(String::from("amd64")), + _ => Err(RubyInstallError::UnsupportedArchitecture(String::from( + consts::ARCH, + ))), + } +} + pub(crate) fn download( uri: impl AsRef, destination: impl AsRef, @@ -183,6 +193,9 @@ pub(crate) enum RubyInstallError { #[error("Invalid base url {0}")] InvalidBaseUrl(String), + #[error("Unsupported architecture: {0}")] + UnsupportedArchitecture(String), + #[error("Could not open file: {0}")] CouldNotOpenFile(std::io::Error), @@ -237,7 +250,7 @@ version = "3.1.3" let out = download_url(&stack_id!("heroku-24"), "3.1.4").unwrap(); assert_eq!( out.as_ref(), - "https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/heroku-24/amd64/ruby-3.1.4.tgz", + format!("https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/heroku-24/{}/ruby-3.1.4.tgz", ruby_arch().unwrap()), ); } } From fd0e254984e08dea7b1370d566abb13986a21062 Mon Sep 17 00:00:00 2001 From: Rune Soerensen Date: Wed, 8 May 2024 09:52:29 -0400 Subject: [PATCH 4/5] Map aarch64 to arm64 --- buildpacks/ruby/src/layers/ruby_install_layer.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 6a7d830b..a83874c2 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -149,6 +149,7 @@ fn download_url(stack: &StackId, version: impl std::fmt::Display) -> Result Result { match consts::ARCH { + "aarch64" => Ok(String::from("arm64")), "x86_64" => Ok(String::from("amd64")), _ => Err(RubyInstallError::UnsupportedArchitecture(String::from( consts::ARCH, From 6c14d0f0119c5655678e13918c99334ef813c37a Mon Sep 17 00:00:00 2001 From: Rune Soerensen Date: Wed, 8 May 2024 09:56:06 -0400 Subject: [PATCH 5/5] Verify ruby arch behavior --- buildpacks/ruby/src/layers/ruby_install_layer.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index a83874c2..15778e9a 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -254,4 +254,12 @@ version = "3.1.3" format!("https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/heroku-24/{}/ruby-3.1.4.tgz", ruby_arch().unwrap()), ); } + + #[test] + fn test_ruby_arch() { + #[cfg(target_arch = "aarch64")] + assert_eq!("arm64", ruby_arch().unwrap()); + #[cfg(target_arch = "x86_64")] + assert_eq!("amd64", ruby_arch().unwrap()); + } }