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 2 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" }
26 changes: 22 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 Down Expand Up @@ -130,10 +131,18 @@ 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("amd64")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great starting point. The only thing I would change is to use the architecture of the current machine. We're doing this in classic via shelling out https://github.com/heroku/heroku-buildpack-ruby/blob/fd6585411cbf86d363ad0824f53d8edba1d7afed/lib/language_pack/base.rb#L45-L57.

I'm hoping on a plane in a few hours and then out tomorrow, if you're available to take a stab at adding that extra logic that would be amazing 🙏🏻. If not, I can take this commit and add that on top.

I was working towards upgrading libcnb first, but seeing how compact this PR is, I think I like the idea of merging this in now and cutting a builder so people can play with it.

Copy link
Member

@edmorley edmorley May 7, 2024

Choose a reason for hiding this comment

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

@runesoerensen @schneems The multi-arch CNB release automation relies upon the buildpack having declared [[targets]] in order to know to create the OCI images and .cnb files (attached to the GitHub release) as multi-arch. As such, adding support for Heroku-24 via [[stacks]] will mean the releases will continue to be single arch and so cannot be added to the heroku/builder:24 builder, since CNBs in there need to support ARM64 too. As such, the priority is to upgrade to newer libcnb.rs and [[targets]].

The only thing I would change is to use the architecture of the current machine. We're doing this in classic via shelling out

We shouldn't shell out for this in our CNBs. We should either:

  1. Use context.target.arch (once the CNB has upgraded libcnb and switched to targets)
  2. Or, use a Rust compile time conditional (https://doc.rust-lang.org/reference/conditional-compilation.html)

See also:
https://salesforce-internal.slack.com/archives/C02GZCPPV38/p1712568024934129?thread_ts=1712073915.519419&cid=C02GZCPPV38

Copy link
Contributor Author

@runesoerensen runesoerensen May 7, 2024

Choose a reason for hiding this comment

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

Yep shelling out is definitely not the best approach here.. This is somewhat related to heroku/buildpacks-nodejs#814 (comment) -- e.g. whether to use the CNB targets, or the compile-time conditional (or std::env::consts::ARCH as in the node.js sample).

I alluded to a conversation I had with @Malax on this (re env provided target arch vs compile-time conditionals) in the other PR. What do you think about this @Malax (and did I remember the conversation correctly :-))?

Copy link
Member

Choose a reason for hiding this comment

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

For Python I used context.target.arch during the build since I have to use other fields from content.target anyway, such as the distro name/version, so it seemed to make sense to use all metadata from the same place:
https://github.com/heroku/buildpacks-python/blob/de378063c83e1eec6302e79f93f189162b5bbbbf/src/python_version.rs#L39-L47

(Though for the tests, I have to use conditional compilation: https://github.com/heroku/buildpacks-python/blob/de378063c83e1eec6302e79f93f189162b5bbbbf/tests/mod.rs#L29-L35)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure, seems like it'd make a lot of sense to also use context.target in this buildpack when the buildpack is updated to newer libcnb.rs and targets.

I've updated this implementation to also factor in the current arch -- should be fairly straightforward to adapt this to use the Target instead.

.push(&filename);
} else {
url.path_segments_mut()
.map_err(|()| RubyInstallError::InvalidBaseUrl(String::from(base)))?
.push(stack)
.push(&filename);
}
Ok(url)
}

Expand Down Expand Up @@ -222,4 +231,13 @@ 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(),
"https://heroku-buildpack-ruby.s3.us-east-1.amazonaws.com/heroku-24/amd64/ruby-3.1.4.tgz",
);
}
}