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..d2a47e5 100644 --- a/buildpacks/php/CHANGELOG.md +++ b/buildpacks/php/CHANGELOG.md @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add PHP/8.3, update PHP runtimes, extensions, Composers, web servers (#104) + +### 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`) +- Bump versions of Composer and minimal PHP for bootstrapping to 2.7.6 and 8.3.7 + ## [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..554ac96 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; @@ -6,8 +7,8 @@ use libcnb::layer_env::Scope; use libcnb::Env; use std::path::PathBuf; -const PHP_VERSION: &str = "8.1.12"; -const COMPOSER_VERSION: &str = "2.4.4"; +const PHP_VERSION: &str = "8.3.7"; +const COMPOSER_VERSION: &str = "2.7.6"; const CLASSIC_BUILDPACK_VERSION: &str = "heads/cnb-installer"; const CLASSIC_BUILDPACK_INSTALLER_SUBDIR: &str = "support/installer"; @@ -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::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::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..c0b7445 100644 --- a/buildpacks/php/src/main.rs +++ b/buildpacks/php/src/main.rs @@ -18,7 +18,9 @@ use crate::package_manager::composer::DependencyInstallationError; use crate::php_project::{ PlatformJsonError, PlatformJsonNotice, ProjectLoadError, ProjectLoaderNotice, }; -use crate::platform::{PlatformRepositoryUrlError, WebserversJsonError}; +use crate::platform::{ + heroku_stack_name_for_target, PlatformRepositoryUrlError, WebserversJsonError, +}; use indoc::formatdoc; use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder}; use libcnb::data::launch::{LaunchBuilder, ProcessBuilder}; @@ -59,6 +61,9 @@ impl Buildpack for PhpBuildpack { } fn build(&self, context: BuildContext) -> libcnb::Result { + let stack_name = heroku_stack_name_for_target(&context.target) + .expect("Internal error: could not determine Heroku stack name for OS/distro"); + let mut loader_notices = Vec::::new(); let loader = php_project::ProjectLoader::from_env(context.platform.env()) .unwrap(&mut loader_notices); @@ -90,12 +95,7 @@ impl Buildpack for PhpBuildpack { let mut platform_json_notices = Vec::::new(); let platform_json = project - .platform_json( - &context.stack_id, - &platform_installer_path, - &all_repos, - false, - ) + .platform_json(&stack_name, &platform_installer_path, &all_repos, false) .map_err(PhpBuildpackError::PlatformJson)? .unwrap(&mut platform_json_notices); // Warned::unwrap() does not panic :) platform_json_notices @@ -116,7 +116,7 @@ impl Buildpack for PhpBuildpack { log_header("Installing web servers"); let webservers_json = platform::webservers_json( - &context.stack_id, + &stack_name, &platform_installer_path, &classic_buildpack_path, &all_repos, diff --git a/buildpacks/php/src/platform.rs b/buildpacks/php/src/platform.rs index 7bf02c6..accda31 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,48 @@ pub(crate) enum PlatformRepositoryUrlError { Parse(url::ParseError), } +pub(crate) fn heroku_stack_name_for_target(target: &Target) -> Result { + let Target { + os, + distro_name, + distro_version, + .. + } = target; + match (os.as_str(), distro_name.as_str(), distro_version.as_str()) { + ("linux", "ubuntu", v @ ("20.04" | "22.04")) => { + Ok(format!("heroku-{}", v.strip_suffix(".04").unwrap_or(v))) + } + _ => Err(format!("{os}-{distro_name}-{distro_version}")), + } +} + +pub(crate) fn platform_base_url_for_target(target: &Target) -> Url { + let Target { + os, + arch, + distro_name, + distro_version, + .. + } = target; + let stack_identifier = if let ("linux", "ubuntu", v) = + (os.as_str(), distro_name.as_str(), distro_version.as_str()) + { + let stack_name = heroku_stack_name_for_target(target) + .expect("Internal error: could not determine Heroku stack name for OS/distro"); + match v { + "20.04" | "22.04" => stack_name, + _ => format!("{stack_name}-{arch}"), + } + } else { + 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 +84,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![platform_base_url_for_target(&context.target)]; // anything user-supplied let user_repos = context diff --git a/buildpacks/php/tests/fixtures/smoke/hello-world/composer.json b/buildpacks/php/tests/fixtures/smoke/hello-world/composer.json index e9a94ef..849b227 100644 --- a/buildpacks/php/tests/fixtures/smoke/hello-world/composer.json +++ b/buildpacks/php/tests/fixtures/smoke/hello-world/composer.json @@ -1,6 +1,6 @@ { "require": { - "php": "8.1.*", + "php": "8.*", "ext-gmp": "*", "ext-intl": "*", "ext-mbstring": "*", diff --git a/buildpacks/php/tests/fixtures/smoke/hello-world/composer.lock b/buildpacks/php/tests/fixtures/smoke/hello-world/composer.lock index c01c7a8..5cd4f5e 100644 --- a/buildpacks/php/tests/fixtures/smoke/hello-world/composer.lock +++ b/buildpacks/php/tests/fixtures/smoke/hello-world/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "767603e605f5ae2ca56f0f0d4e2d5f21", + "content-hash": "0c2875f1f824866b345f0f523e3ae428", "packages": [ { "name": "alrik11es/cowsayphp", @@ -110,16 +110,16 @@ }, { "name": "bramus/monolog-colored-line-formatter", - "version": "3.1.1", + "version": "3.1.2", "source": { "type": "git", "url": "https://github.com/bramus/monolog-colored-line-formatter.git", - "reference": "bbbffb43b0cbfff5cb6bb8e2c1dd15c99de8bd32" + "reference": "1ce52a13d5accdc425fb912f9b96c84f6be2ea72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bramus/monolog-colored-line-formatter/zipball/bbbffb43b0cbfff5cb6bb8e2c1dd15c99de8bd32", - "reference": "bbbffb43b0cbfff5cb6bb8e2c1dd15c99de8bd32", + "url": "https://api.github.com/repos/bramus/monolog-colored-line-formatter/zipball/1ce52a13d5accdc425fb912f9b96c84f6be2ea72", + "reference": "1ce52a13d5accdc425fb912f9b96c84f6be2ea72", "shasum": "" }, "require": { @@ -150,7 +150,7 @@ "description": "Colored Line Formatter for Monolog", "support": { "issues": "https://github.com/bramus/monolog-colored-line-formatter/issues", - "source": "https://github.com/bramus/monolog-colored-line-formatter/tree/3.1.1" + "source": "https://github.com/bramus/monolog-colored-line-formatter/tree/3.1.2" }, "funding": [ { @@ -158,20 +158,20 @@ "type": "github" } ], - "time": "2023-04-11T12:52:29+00:00" + "time": "2023-08-18T13:44:29+00:00" }, { "name": "monolog/monolog", - "version": "3.3.1", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "9b5daeaffce5b926cac47923798bba91059e60e2" + "reference": "4b18b21a5527a3d5ffdac2fd35d3ab25a9597654" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/9b5daeaffce5b926cac47923798bba91059e60e2", - "reference": "9b5daeaffce5b926cac47923798bba91059e60e2", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/4b18b21a5527a3d5ffdac2fd35d3ab25a9597654", + "reference": "4b18b21a5527a3d5ffdac2fd35d3ab25a9597654", "shasum": "" }, "require": { @@ -186,7 +186,7 @@ "doctrine/couchdb": "~1.0@dev", "elasticsearch/elasticsearch": "^7 || ^8", "ext-json": "*", - "graylog2/gelf-php": "^1.4.2 || ^2@dev", + "graylog2/gelf-php": "^1.4.2 || ^2.0", "guzzlehttp/guzzle": "^7.4.5", "guzzlehttp/psr7": "^2.2", "mongodb/mongodb": "^1.8", @@ -194,7 +194,7 @@ "phpstan/phpstan": "^1.9", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-strict-rules": "^1.4", - "phpunit/phpunit": "^9.5.26", + "phpunit/phpunit": "^10.5.17", "predis/predis": "^1.1 || ^2", "ruflin/elastica": "^7", "symfony/mailer": "^5.4 || ^6", @@ -247,7 +247,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/3.3.1" + "source": "https://github.com/Seldaek/monolog/tree/3.6.0" }, "funding": [ { @@ -259,7 +259,7 @@ "type": "tidelift" } ], - "time": "2023-02-06T13:46:10+00:00" + "time": "2024-04-12T21:02:21+00:00" }, { "name": "psr/log", @@ -313,16 +313,16 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.27.0", + "version": "v1.29.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9773676c8a1bb1f8d4340a62efe641cf76eda7ec", + "reference": "9773676c8a1bb1f8d4340a62efe641cf76eda7ec", "shasum": "" }, "require": { @@ -336,9 +336,6 @@ }, "type": "library", "extra": { - "branch-alias": { - "dev-main": "1.27-dev" - }, "thanks": { "name": "symfony/polyfill", "url": "https://github.com/symfony/polyfill" @@ -376,7 +373,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.29.0" }, "funding": [ { @@ -392,7 +389,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2024-01-29T20:11:03+00:00" } ], "packages-dev": [], @@ -402,7 +399,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "8.1.*", + "php": "8.*", "ext-gmp": "*", "ext-intl": "*", "ext-mbstring": "*", @@ -413,5 +410,5 @@ "ext-pq": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" }