Skip to content

Commit

Permalink
Set target when packaging buildpack (#237)
Browse files Browse the repository at this point in the history
We're seeing some releases with extra `{os}-{arch}` suffixes on the
`.cnb` files, and duplicated copies of `.cnb` files:

- https://github.com/heroku/buildpacks-procfile/releases/tag/v3.1.2
- https://github.com/heroku/buildpacks-python/releases/tag/v0.11.0
- https://github.com/heroku/buildpacks-python/releases/tag/v0.12.0

This seems to be happening because newer versions of pack with
multi-arch support are detecting these buildpacks as multi-arch
buildpacks, and thus tries to build a `"{os}-{arch}.cnb"` for each of
the targets:
https://github.com/buildpacks/pack/pull/2086/files#diff-f149889a3ad04f6ef0e49a7bc274d34be83c6e9ce07539c4ad4c65561fdc7bbaR184-R185

This PR forces `pack buildpack package` to use a `--target` argument,
like `--target linux/amd64` which causes `pack` to skip a bunch of the
multi-arch concerns (multi-arch concerns are already handled by this
automation) like these suffixes.
  • Loading branch information
joshwlewis committed Jul 3, 2024
1 parent 59828f1 commit e6071f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/_buildpacks-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ jobs:
for target in $(jq --exit-status -c ".targets | .[]" <<< "${buildpack}"); do
output_dir=$(jq --exit-status -r ".output_dir" <<< "${target}")
cnb_file=$(jq --exit-status -r ".cnb_file" <<< "${target}")
pack buildpack package "$cnb_file" --config "${output_dir}/package.toml" --format file --verbose
oci_target=$(jq --exit-status -r ".oci_target" <<< "${target}")
pack buildpack package "$cnb_file" --target "${oci_target}" --config "${output_dir}/package.toml" --format file --verbose
done
done
Expand Down
13 changes: 13 additions & 0 deletions src/commands/generate_buildpack_matrix/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub(crate) struct TargetInfo {
os: Option<String>,
arch: Option<String>,
rust_triple: Option<String>,
oci_target: String,
cnb_file: String,
stable_tag: String,
temporary_tag: String,
Expand Down Expand Up @@ -161,6 +162,7 @@ pub(crate) fn read_buildpack_info(
Ok(TargetInfo {
cnb_file: cnb_file(&buildpack_descriptor.buildpack().id, suffix.as_deref()),
os: target.os.clone(),
oci_target: oci_target(target),
arch: target.arch.clone(),
output_dir: target_output_dir(
&buildpack_descriptor.buildpack().id,
Expand Down Expand Up @@ -220,6 +222,15 @@ fn cnb_file(buildpack_id: &BuildpackId, suffix: Option<&str>) -> String {
)
}

// Returns the OCI target name for a buildpack target. Currently ignores distros.
fn oci_target(target: &BuildpackTarget) -> String {
match (target.os.as_deref(), target.arch.as_deref()) {
(Some(os), Some(arch)) => format!("{os}/{arch}"),
(Some(os), None) => os.to_string(),
(None, _) => String::new(),
}
}

// Returns the target naming suffix for image tags and .cnb files.
fn target_name(target: &BuildpackTarget) -> String {
match (target.os.as_deref(), target.arch.as_deref()) {
Expand Down Expand Up @@ -374,6 +385,8 @@ mod tests {
bp_info.targets[1].rust_triple,
Some("aarch64-unknown-linux-musl".to_string())
);
assert_eq!(bp_info.targets[0].oci_target, "linux/amd64");
assert_eq!(bp_info.targets[1].oci_target, "linux/arm64");
assert_eq!(
bp_info.targets[0].temporary_tag,
"docker.io/heroku/buildpack-fakey:_918273_linux-amd64"
Expand Down

0 comments on commit e6071f8

Please sign in to comment.