Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support heroku-24 #280

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions buildpacks/ruby/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions buildpacks/ruby/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ id = "heroku-20"
[[stacks]]
id = "heroku-22"

[[stacks]]
id = "heroku-24"

[metadata.release]
image = { repository = "docker.io/heroku/buildpack-ruby" }
48 changes: 44 additions & 4 deletions buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,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;
Expand Down Expand Up @@ -130,13 +132,31 @@ fn download_url(stack: &StackId, version: impl std::fmt::Display) -> Result<Url,
let base = "https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com";
let mut url = Url::parse(base).map_err(RubyInstallError::UrlParseError)?;

url.path_segments_mut()
.map_err(|()| RubyInstallError::InvalidBaseUrl(String::from(base)))?
.push(stack)
.push(&filename);
if stack == &stack_id!("heroku-24") {
url.path_segments_mut()
.map_err(|()| RubyInstallError::InvalidBaseUrl(String::from(base)))?
.push(stack)
.push(&ruby_arch()?)
.push(&filename);
} else {
url.path_segments_mut()
.map_err(|()| RubyInstallError::InvalidBaseUrl(String::from(base)))?
.push(stack)
.push(&filename);
}
Ok(url)
}

fn ruby_arch() -> Result<String, RubyInstallError> {
match consts::ARCH {
"aarch64" => Ok(String::from("arm64")),
"x86_64" => Ok(String::from("amd64")),
_ => Err(RubyInstallError::UnsupportedArchitecture(String::from(
consts::ARCH,
))),
}
}

pub(crate) fn download(
uri: impl AsRef<str>,
destination: impl AsRef<Path>,
Expand Down Expand Up @@ -174,6 +194,9 @@ pub(crate) enum RubyInstallError {
#[error("Invalid base url {0}")]
InvalidBaseUrl(String),

#[error("Unsupported architecture: {0}")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want to go a little above and beyond and list out the supported architectures.

In general, any time we're failing because a value was unexpected based on a list of currently known/supported values, I want to output both what was actually output (the current architecture) but also what was expected (either arm64 or amd64 etc.)

This can help the future development errors/issues for example if someone accidentally adds a space like " arm64". Even if we think such an issue would be rare, I don't see a downside in adding that information to the error message (other than that requirement will influence the implementation, such as needing to move the information to a const, for example.

UnsupportedArchitecture(String),

#[error("Could not open file: {0}")]
CouldNotOpenFile(std::io::Error),

Expand Down Expand Up @@ -222,4 +245,21 @@ version = "3.1.3"
"https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/heroku-20/ruby-2.7.4.tgz",
);
}

#[test]
fn test_heroku24_ruby_url() {
let out = download_url(&stack_id!("heroku-24"), "3.1.4").unwrap();
assert_eq!(
out.as_ref(),
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());
}
}