Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set processes when Procfile is present #319

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions buildpacks/go/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
17 changes: 11 additions & 6 deletions buildpacks/go/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,11 +139,16 @@ 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![];
joshwlewis marked this conversation as resolved.
Show resolved Hide resolved
if Path::exists(&context.app_dir.join("Procfile")) {
log_info("Skipping launch process registration (Procfile detected)");
} else {
log_header("Registering launch processes");
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()
Expand Down
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)
}
14 changes: 14 additions & 0 deletions buildpacks/go/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand All @@ -141,6 +142,19 @@ 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_contains!(ctx.pack_stdout, "Skipping launch process registration");
assert_not_contains!(ctx.pack_stdout, "Registering launch processes");
assert_not_contains!(ctx.pack_stdout, "Detected processes:");
});
}

#[test]
#[ignore = "integration test"]
fn test_vendor_fasthttp_120() {
Expand Down