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 050f2f1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
3 changes: 3 additions & 0 deletions buildpacks/go/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ 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
15 changes: 9 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,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()
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/basic_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, "basic_http_122")
}

func main() {
port := os.Getenv("PORT")
if port == "" { port = "8080" }

http.HandleFunc("/", root)
http.ListenAndServe(":" + port, nil)
}
17 changes: 16 additions & 1 deletion buildpacks/go/tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Required due to: https://github.com/rust-lang/rust/issues/95513
#![allow(unused_crate_dependencies)]

use libcnb_test::{assert_contains, assert_not_contains, BuildConfig, ContainerConfig, TestRunner};
use libcnb_test::{
assert_contains, assert_not_contains, BuildConfig, BuildpackReference, ContainerConfig,
TestRunner,
};
use std::{env::consts, time::Duration};

const DEFAULT_BUILDER: &str = "heroku/builder:24";
Expand Down Expand Up @@ -141,6 +144,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() {
Expand Down

0 comments on commit 050f2f1

Please sign in to comment.