diff --git a/Cargo.lock b/Cargo.lock index 83483eb..1d9f52c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,7 +166,7 @@ dependencies = [ "iana-time-zone", "num-traits", "serde", - "windows-targets 0.52.5", + "windows-targets", ] [[package]] @@ -346,7 +346,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -360,12 +360,13 @@ dependencies = [ [[package]] name = "fancy-regex" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7493d4c459da9f84325ad297371a6b2b8a162800873a22e3b6b6512e61d18c05" +checksum = "531e46835a22af56d1e3b66f04844bed63158bc094a628bec1d321d9b4c44bf2" dependencies = [ "bit-set", - "regex", + "regex-automata", + "regex-syntax", ] [[package]] @@ -396,7 +397,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -485,7 +486,7 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -600,9 +601,9 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libcnb" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c385c618fa8afebe2d1b499b74bc0a3682507b0d91aa4aad09708b81681e2ca" +checksum = "aacc89bfeaef5f43cdee664798e3c0aa36e052a412ab1391f0750aee4df1f407" dependencies = [ "libcnb-common", "libcnb-data", @@ -614,9 +615,9 @@ dependencies = [ [[package]] name = "libcnb-common" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28fede7cd4353004ff1976ce66c34bb266fa35095be12c6d3d4c2358ef790778" +checksum = "a356bd77381b51f1ca42450694f4c7d1c7533a57c5f6a49553a96af96963b6e3" dependencies = [ "serde", "thiserror", @@ -625,9 +626,9 @@ dependencies = [ [[package]] name = "libcnb-data" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20c0c825002ee57279d0c9e23309863804536f0c45687436d574dd3e8c7420fb" +checksum = "dfcd102bfb1bf98ee4c18da0b29be6f23a19681937924bf758e9ea8499668b18" dependencies = [ "fancy-regex", "libcnb-proc-macros", @@ -639,12 +640,13 @@ dependencies = [ [[package]] name = "libcnb-package" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "934ec4398991f7e926889a6e5046d83935e39de5c047feb591ed0333b83abf75" +checksum = "3b8d9b42112212a875c07fb3acf19504cf330edaa63cddd1823e9d03a5e2b934" dependencies = [ "cargo_metadata", "ignore", + "indoc", "libcnb-common", "libcnb-data", "petgraph", @@ -655,9 +657,9 @@ dependencies = [ [[package]] name = "libcnb-proc-macros" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0f0afde3a7327936afd743e2cb52f6de3a0d4a4894f6f13bdae1a41e6879c17" +checksum = "f83bba477c3a6cd69b29f77a6591411bac15ab7b341ad3d3cd38943bfbbd412f" dependencies = [ "cargo_metadata", "fancy-regex", @@ -667,9 +669,9 @@ dependencies = [ [[package]] name = "libcnb-test" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2471f098af746db385e0e254dd423de21db3347ea26cfd4c758a37cccaa1674a" +checksum = "9471152703833b74d565c7f7c910b4d5e084f955c327eba2bdb6658e86bd6dd6" dependencies = [ "fastrand", "fs_extra", @@ -682,9 +684,9 @@ dependencies = [ [[package]] name = "libherokubuildpack" -version = "0.17.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e800ca80376b707d57d55ea95f48c88d2621864a0250cc41f54eab8e9481887" +checksum = "146f61983fd384cb5ab5373acdd8f53fcb4b27ecb200435a6bfb6a70b421bc9d" dependencies = [ "termcolor", ] @@ -927,7 +929,7 @@ dependencies = [ "libc", "spin", "untrusted", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -949,7 +951,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1151,7 +1153,7 @@ dependencies = [ "cfg-if", "fastrand", "rustix", - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1442,15 +1444,14 @@ dependencies = [ [[package]] name = "which" -version = "5.0.0" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14" +checksum = "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7" dependencies = [ "either", "home", - "once_cell", "rustix", - "windows-sys 0.48.0", + "winsafe", ] [[package]] @@ -1459,7 +1460,7 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "windows-sys 0.52.0", + "windows-sys", ] [[package]] @@ -1468,16 +1469,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", + "windows-targets", ] [[package]] @@ -1486,22 +1478,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -1510,46 +1487,28 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -1562,48 +1521,24 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" @@ -1612,13 +1547,19 @@ checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.9" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86c949fede1d13936a99f14fafd3e76fd642b556dd2ce96287fbe2e0151bfac6" +checksum = "56c52728401e1dc672a56e81e593e912aa54c78f40246869f78359a2bf24d29d" dependencies = [ "memchr", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "zeroize" version = "1.8.1" diff --git a/buildpacks/php/CHANGELOG.md b/buildpacks/php/CHANGELOG.md index 97aa15d..d359a33 100644 --- a/buildpacks/php/CHANGELOG.md +++ b/buildpacks/php/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Use Buildpack API 0.10 (requires `lifecycle` 0.17 or newer) +- `buildpack.toml` declaration of `[[stacks]]` has been replaced with `[[targets]]`, currently supporting Ubuntu 20.04 and 22.04 (both `amd64`) + ## [0.1.2] - 2023-10-24 ### Changed diff --git a/buildpacks/php/Cargo.toml b/buildpacks/php/Cargo.toml index 6973b91..c62c5ca 100644 --- a/buildpacks/php/Cargo.toml +++ b/buildpacks/php/Cargo.toml @@ -15,8 +15,8 @@ flate2 = { version = "1", default-features = false, features = ["zlib"] } indoc = "2" # libcnb has a much bigger impact on buildpack behaviour than any other dependencies, # so it's pinned to an exact version to isolate it from lockfile refreshes. -libcnb = "=0.17.0" -libherokubuildpack = { version = "=0.17.0", default-features = false, features = ["log"] } +libcnb = "=0.21.0" +libherokubuildpack = { version = "=0.21.0", default-features = false, features = ["log"] } regex = "1" serde = { version = "1", features = ["derive"] } serde_json = "1" @@ -30,4 +30,4 @@ warned = "0.1" assert-json-diff = "2" exponential-backoff = "1" figment = { version = "0.10", features = ["toml"] } -libcnb-test = "=0.17.0" +libcnb-test = "=0.21.0" diff --git a/buildpacks/php/buildpack.toml b/buildpacks/php/buildpack.toml index 37e8dcd..4407e6b 100644 --- a/buildpacks/php/buildpack.toml +++ b/buildpacks/php/buildpack.toml @@ -1,4 +1,4 @@ -api = "0.9" +api = "0.10" [buildpack] id = "heroku/php" @@ -7,16 +7,21 @@ name = "Heroku PHP" homepage = "https://github.com/heroku/buildpacks-php" description = "Heroku's buildpack for PHP applications." keywords = ["php", "heroku"] -clear-env = true [[buildpack.licenses]] type = "BSD-3-Clause" -[[stacks]] -id = "heroku-20" +[[targets]] +os = "linux" +arch = "amd64" -[[stacks]] -id = "heroku-22" +[[targets.distros]] +name = "ubuntu" +version = "20.04" + +[[targets.distros]] +name = "ubuntu" +version = "22.04" [metadata.release] image = { repository = "docker.io/heroku/buildpack-php" } diff --git a/buildpacks/php/src/bootstrap.rs b/buildpacks/php/src/bootstrap.rs index 47a9ac8..08c9c86 100644 --- a/buildpacks/php/src/bootstrap.rs +++ b/buildpacks/php/src/bootstrap.rs @@ -1,4 +1,5 @@ use crate::layers::bootstrap::BootstrapLayer; +use crate::platform; use crate::PhpBuildpack; use libcnb::build::BuildContext; use libcnb::data::layer_name; @@ -25,10 +26,10 @@ pub(crate) fn bootstrap( let php_layer_data = context.handle_layer( layer_name!("bootstrap_php"), BootstrapLayer { - url: format!( - "https://lang-php.s3.us-east-1.amazonaws.com/dist-{}-stable/php-min-{}.tar.gz", - context.stack_id, PHP_VERSION - ), + url: platform::get_platform_base_url_for_target(&context.target) + .join(&format!("php-min-{PHP_VERSION}.tar.gz")) + .expect("Internal error: failed to generate bootstrap download URL for PHP") + .to_string(), strip_path_components: 0, directory: PathBuf::new(), }, @@ -38,10 +39,10 @@ pub(crate) fn bootstrap( let composer_layer_data = context.handle_layer( layer_name!("bootstrap_composer"), BootstrapLayer { - url: format!( - "https://lang-php.s3.us-east-1.amazonaws.com/dist-{}-stable/composer-{}.tar.gz", - context.stack_id, COMPOSER_VERSION - ), + url: platform::get_platform_base_url_for_target(&context.target) + .join(&format!("composer-{COMPOSER_VERSION}.tar.gz")) + .expect("Internal error: failed to generate bootstrap download URL for Composer") + .to_string(), strip_path_components: 0, directory: PathBuf::new(), }, diff --git a/buildpacks/php/src/layers/bootstrap.rs b/buildpacks/php/src/layers/bootstrap.rs index ea0ced1..be50e4a 100644 --- a/buildpacks/php/src/layers/bootstrap.rs +++ b/buildpacks/php/src/layers/bootstrap.rs @@ -1,16 +1,17 @@ use crate::utils; use crate::{PhpBuildpack, PhpBuildpackError}; use libcnb::build::BuildContext; -use libcnb::data::buildpack::StackId; use libcnb::data::layer_content_metadata::LayerTypes; use libcnb::layer::{ExistingLayerStrategy, Layer, LayerData, LayerResult, LayerResultBuilder}; -use libcnb::Buildpack; +use libcnb::{Buildpack, Target}; use serde::{Deserialize, Serialize}; use std::path::{Path, PathBuf}; #[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] pub(crate) struct BootstrapLayerMetadata { - stack: StackId, + arch: String, + distro_name: String, + distro_version: String, url: String, strip_path_components: usize, directory: PathBuf, @@ -35,7 +36,7 @@ impl Layer for BootstrapLayer { } fn create( - &self, + &mut self, context: &BuildContext, layer_path: &Path, ) -> Result, ::Error> { @@ -48,7 +49,7 @@ impl Layer for BootstrapLayer { .map_err(BootstrapLayerError::DownloadUnpack)?; let layer_metadata = generate_layer_metadata( - &context.stack_id, + &context.target, &self.url, self.strip_path_components, &self.directory, @@ -57,13 +58,13 @@ impl Layer for BootstrapLayer { } fn existing_layer_strategy( - &self, + &mut self, context: &BuildContext, layer_data: &LayerData, ) -> Result::Error> { let old_metadata = &layer_data.content_metadata.metadata; let new_metadata = generate_layer_metadata( - &context.stack_id, + &context.target, &self.url, self.strip_path_components, &self.directory, @@ -77,13 +78,15 @@ impl Layer for BootstrapLayer { } fn generate_layer_metadata( - stack: &StackId, + target: &Target, url: &str, strip_path_components: usize, directory: &Path, ) -> BootstrapLayerMetadata { BootstrapLayerMetadata { - stack: stack.clone(), + arch: target.arch.clone(), + distro_name: target.distro_name.clone(), + distro_version: target.distro_version.clone(), url: url.to_string(), strip_path_components, directory: directory.to_path_buf(), diff --git a/buildpacks/php/src/layers/composer_cache.rs b/buildpacks/php/src/layers/composer_cache.rs index 78897b9..10c7a07 100644 --- a/buildpacks/php/src/layers/composer_cache.rs +++ b/buildpacks/php/src/layers/composer_cache.rs @@ -22,7 +22,7 @@ impl Layer for ComposerCacheLayer { } fn create( - &self, + &mut self, _context: &BuildContext, layer_path: &Path, ) -> Result, ::Error> { @@ -37,7 +37,7 @@ impl Layer for ComposerCacheLayer { } fn existing_layer_strategy( - &self, + &mut self, _context: &BuildContext, _layer_data: &LayerData, ) -> Result::Error> { diff --git a/buildpacks/php/src/layers/composer_env.rs b/buildpacks/php/src/layers/composer_env.rs index 7e4fe18..d63289e 100644 --- a/buildpacks/php/src/layers/composer_env.rs +++ b/buildpacks/php/src/layers/composer_env.rs @@ -26,7 +26,7 @@ impl Layer for ComposerEnvLayer<'_> { } fn create( - &self, + &mut self, _context: &BuildContext, _layer_path: &Path, ) -> Result, ::Error> { diff --git a/buildpacks/php/src/layers/platform.rs b/buildpacks/php/src/layers/platform.rs index bbf4bab..4fd23e1 100644 --- a/buildpacks/php/src/layers/platform.rs +++ b/buildpacks/php/src/layers/platform.rs @@ -2,11 +2,10 @@ use crate::utils::{self, CommandError}; use crate::{PhpBuildpack, PhpBuildpackError}; use composer::ComposerRootPackage; use libcnb::build::BuildContext; -use libcnb::data::buildpack::StackId; use libcnb::data::layer_content_metadata::LayerTypes; use libcnb::layer::{Layer, LayerResult, LayerResultBuilder}; use libcnb::layer_env::{LayerEnv, ModificationBehavior, Scope}; -use libcnb::{Buildpack, Env}; +use libcnb::{Buildpack, Env, Target}; use libherokubuildpack::log::log_info; use serde::de::{Error, Unexpected}; use serde::{Deserialize, Deserializer, Serialize}; @@ -17,7 +16,9 @@ use std::process::Command; #[derive(Clone, Debug, Deserialize, Serialize)] pub(crate) struct PlatformLayerMetadata { - stack: StackId, + arch: String, + distro_name: String, + distro_version: String, } pub(crate) struct PlatformLayer<'a> { @@ -38,7 +39,7 @@ impl Layer for PlatformLayer<'_> { } fn create( - &self, + &mut self, context: &BuildContext, layer_path: &Path, ) -> Result, ::Error> { @@ -143,16 +144,18 @@ impl Layer for PlatformLayer<'_> { } } - let layer_metadata = generate_layer_metadata(&context.stack_id); + let layer_metadata = generate_layer_metadata(&context.target); LayerResultBuilder::new(layer_metadata) .env(layer_env) .build() } } -fn generate_layer_metadata(stack_id: &StackId) -> PlatformLayerMetadata { +fn generate_layer_metadata(target: &Target) -> PlatformLayerMetadata { PlatformLayerMetadata { - stack: stack_id.clone(), + arch: target.arch.clone(), + distro_name: target.distro_name.clone(), + distro_version: target.distro_version.clone(), } } diff --git a/buildpacks/php/src/main.rs b/buildpacks/php/src/main.rs index 86be854..a549696 100644 --- a/buildpacks/php/src/main.rs +++ b/buildpacks/php/src/main.rs @@ -18,7 +18,7 @@ use crate::package_manager::composer::DependencyInstallationError; use crate::php_project::{ PlatformJsonError, PlatformJsonNotice, ProjectLoadError, ProjectLoaderNotice, }; -use crate::platform::{PlatformRepositoryUrlError, WebserversJsonError}; +use crate::platform::{get_stack_name_for_target, PlatformRepositoryUrlError, WebserversJsonError}; use indoc::formatdoc; use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder}; use libcnb::data::launch::{LaunchBuilder, ProcessBuilder}; @@ -91,7 +91,7 @@ impl Buildpack for PhpBuildpack { let mut platform_json_notices = Vec::::new(); let platform_json = project .platform_json( - &context.stack_id, + &get_stack_name_for_target(&context.target), &platform_installer_path, &all_repos, false, @@ -116,7 +116,7 @@ impl Buildpack for PhpBuildpack { log_header("Installing web servers"); let webservers_json = platform::webservers_json( - &context.stack_id, + &get_stack_name_for_target(&context.target), &platform_installer_path, &classic_buildpack_path, &all_repos, diff --git a/buildpacks/php/src/platform.rs b/buildpacks/php/src/platform.rs index 7bf02c6..a69a378 100644 --- a/buildpacks/php/src/platform.rs +++ b/buildpacks/php/src/platform.rs @@ -4,7 +4,7 @@ use crate::platform::generator::PlatformGeneratorError; use crate::PhpBuildpack; use composer::ComposerRootPackage; use libcnb::build::BuildContext; -use libcnb::Platform; +use libcnb::{Platform, Target}; use serde_json::json; use std::collections::HashMap; use std::path::Path; @@ -33,6 +33,62 @@ pub(crate) enum PlatformRepositoryUrlError { Parse(url::ParseError), } +pub(crate) fn get_stack_name_for_target(target: &Target) -> String { + match target { + Target { + os, + distro_name, + distro_version, + .. + } if os == "linux" && distro_name == "ubuntu" => format!( + "heroku-{}", + distro_version.strip_suffix(".04").unwrap_or(distro_version) + ), + Target { + os, + distro_name, + distro_version, + .. + } => format!("{os}-{distro_name}-{distro_version}"), + } +} + +pub(crate) fn get_platform_base_url_for_target(target: &Target) -> Url { + let stack_identifier = match target { + Target { + os, + distro_name, + distro_version, + .. + } if os == "linux" + && distro_name == "ubuntu" + && (distro_version == "20.04" || distro_version == "22.04") => + { + get_stack_name_for_target(target) + } + Target { + os, + arch, + distro_name, + .. + } if os == "linux" && distro_name == "ubuntu" => { + format!("{}-{}", get_stack_name_for_target(target), arch) + } + Target { + os, + arch, + distro_name, + distro_version, + .. + } => format!("{os}-{arch}-{distro_name}-{distro_version}"), + }; + + Url::parse(&format!( + "https://lang-php.s3.us-east-1.amazonaws.com/dist-{stack_identifier}-cnb/", + )) + .expect("Internal error: failed to generate default repository URL") +} + /// Returns a list of platform repository [`Url`s](Url), computed from the given [`BuildContext`]'s /// stack ID and processed `HEROKU_PHP_PLATFORM_REPOSITORIES` environment variable. /// @@ -42,11 +98,7 @@ pub(crate) fn platform_repository_urls_from_default_and_build_context( context: &BuildContext, ) -> Result, PlatformRepositoryUrlError> { // our default repo - let default_platform_repositories = vec![Url::parse(&format!( - "https://lang-php.s3.us-east-1.amazonaws.com/dist-{}-cnb/", - context.stack_id, - )) - .expect("Internal error: failed to parse default repository URL")]; + let default_platform_repositories = vec![get_platform_base_url_for_target(&context.target)]; // anything user-supplied let user_repos = context