diff --git a/buildpacks/go/CHANGELOG.md b/buildpacks/go/CHANGELOG.md index 9e482b32..e62ce686 100644 --- a/buildpacks/go/CHANGELOG.md +++ b/buildpacks/go/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Now prefers processes set by Procfile, and no longer adds it's own processes if a Procfile is present. + ## [0.4.7] - 2024-12-06 - Added go1.22.10 (linux-amd64), go1.22.10 (linux-arm64), go1.23.4 (linux-amd64), go1.23.4 (linux-arm64). diff --git a/buildpacks/go/src/main.rs b/buildpacks/go/src/main.rs index 0a458ed4..651df8d2 100644 --- a/buildpacks/go/src/main.rs +++ b/buildpacks/go/src/main.rs @@ -11,7 +11,7 @@ use layers::dist::{DistLayer, DistLayerError}; use layers::target::{TargetLayer, TargetLayerError}; use libcnb::build::{BuildContext, BuildResult, BuildResultBuilder}; use libcnb::data::build_plan::BuildPlanBuilder; -use libcnb::data::launch::LaunchBuilder; +use libcnb::data::launch::{LaunchBuilder, Process}; use libcnb::data::layer_name; use libcnb::detect::{DetectContext, DetectResult, DetectResultBuilder}; use libcnb::generic::GenericMetadata; @@ -139,11 +139,14 @@ impl Buildpack for GoBuildpack { } cmd::go_install(&packages, &go_env).map_err(GoBuildpackError::GoBuild)?; - log_header("Setting launch table"); - let procs = proc::build_procs(&packages).map_err(GoBuildpackError::Proc)?; - log_info("Detected processes:"); - for proc in &procs { - log_info(format!(" - {}: {}", proc.r#type, proc.command.join(" "))); + let mut procs: Vec = vec![]; + if !Path::exists(&context.app_dir.join("Procfile")) { + log_header("Setting launch table"); + procs = proc::build_procs(&packages).map_err(GoBuildpackError::Proc)?; + log_info("Detected processes:"); + for proc in &procs { + log_info(format!(" - {}: {}", proc.r#type, proc.command.join(" "))); + } } BuildResultBuilder::new() diff --git a/buildpacks/go/tests/fixtures/procfile_http_123/Procfile b/buildpacks/go/tests/fixtures/procfile_http_123/Procfile new file mode 100644 index 00000000..4d97e877 --- /dev/null +++ b/buildpacks/go/tests/fixtures/procfile_http_123/Procfile @@ -0,0 +1 @@ +web: procfile_http_123 diff --git a/buildpacks/go/tests/fixtures/procfile_http_123/go.mod b/buildpacks/go/tests/fixtures/procfile_http_123/go.mod new file mode 100644 index 00000000..e14d58fe --- /dev/null +++ b/buildpacks/go/tests/fixtures/procfile_http_123/go.mod @@ -0,0 +1,3 @@ +module example.com/procfile_http_123 + +go 1.23 diff --git a/buildpacks/go/tests/fixtures/procfile_http_123/main.go b/buildpacks/go/tests/fixtures/procfile_http_123/main.go new file mode 100644 index 00000000..30eb36a5 --- /dev/null +++ b/buildpacks/go/tests/fixtures/procfile_http_123/main.go @@ -0,0 +1,21 @@ +// +build heroku + +package main + +import ( + "fmt" + "os" + "net/http" +) + +func root(w http.ResponseWriter, req *http.Request) { + fmt.Fprintf(w, "procfile_http_123") +} + +func main() { + port := os.Getenv("PORT") + if port == "" { port = "8080" } + + http.HandleFunc("/", root) + http.ListenAndServe(":" + port, nil) +} diff --git a/buildpacks/go/tests/integration_test.rs b/buildpacks/go/tests/integration_test.rs index 3f1581df..5963c0c6 100644 --- a/buildpacks/go/tests/integration_test.rs +++ b/buildpacks/go/tests/integration_test.rs @@ -121,6 +121,7 @@ fn test_worker_http_118() { &[ "Detected Go version requirement: ~1.18.1", "Installing go1.18.", + "Detected processes", "example.com/worker_http_118/cmd/web", "example.com/worker_http_118/cmd/worker", ], @@ -141,6 +142,18 @@ fn test_basic_http_119() { ); } +#[test] +#[ignore = "integration test"] +fn test_procfile_http_123() { + let build_config: BuildConfig = IntegrationTestConfig::new("procfile_http_123").into(); + TestRunner::default().build(build_config, |ctx| { + assert_contains!(ctx.pack_stdout, "Detected Go version requirement: =1.23"); + assert_contains!(ctx.pack_stdout, "Installing go1.23."); + assert_not_contains!(ctx.pack_stdout, "Setting launch table"); + assert_not_contains!(ctx.pack_stdout, "Detected processes:"); + }); +} + #[test] #[ignore = "integration test"] fn test_vendor_fasthttp_120() {