Skip to content

Commit

Permalink
Don't set processes when Procfile is present
Browse files Browse the repository at this point in the history
  • Loading branch information
joshwlewis committed Dec 12, 2024
1 parent a2303f3 commit 586dc16
Showing 6 changed files with 49 additions and 6 deletions.
2 changes: 2 additions & 0 deletions buildpacks/go/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
15 changes: 9 additions & 6 deletions buildpacks/go/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<Process> = 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()
1 change: 1 addition & 0 deletions buildpacks/go/tests/fixtures/procfile_http_123/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: procfile_http_123
3 changes: 3 additions & 0 deletions buildpacks/go/tests/fixtures/procfile_http_123/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/procfile_http_123

go 1.23
21 changes: 21 additions & 0 deletions buildpacks/go/tests/fixtures/procfile_http_123/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
13 changes: 13 additions & 0 deletions buildpacks/go/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -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() {

0 comments on commit 586dc16

Please sign in to comment.