Skip to content

Commit 43dfb7f

Browse files
Skip process registration with Procfile (#185)
1 parent 27b5ac7 commit 43dfb7f

File tree

8 files changed

+114
-11
lines changed

8 files changed

+114
-11
lines changed

buildpacks/dotnet/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Detected process types are now only registered as launch processes when no Procfile is present. [#185](https://github.com/heroku/buildpacks-dotnet/pull/185)
13+
1014
### Added
1115

1216
- Enabled `libcnb`'s `trace` feature. [#184](https://github.com/heroku/buildpacks-dotnet/pull/184)

buildpacks/dotnet/src/main.rs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,33 @@ impl Buildpack for DotnetBuildpack {
158158
layers::runtime::handle(&context, &sdk_layer.path())?;
159159

160160
log_bullet = log
161-
.bullet("Setting launch table")
161+
.bullet("Process types")
162162
.sub_bullet("Detecting process types from published artifacts");
163163
let mut launch_builder = LaunchBuilder::new();
164164
log = match launch_process::detect_solution_processes(&solution) {
165165
Ok(processes) => {
166166
if processes.is_empty() {
167-
log_bullet = log_bullet.sub_bullet("No processes were detected");
168-
}
169-
for process in processes {
170-
log_bullet = log_bullet.sub_bullet(format!(
171-
"Added {}: {}",
172-
style::value(process.r#type.to_string()),
173-
process.command.join(" ")
174-
));
175-
launch_builder.process(process);
167+
log_bullet.sub_bullet("No processes were detected").done()
168+
} else {
169+
for process in &processes {
170+
log_bullet = log_bullet.sub_bullet(format!(
171+
"Found {}: {}",
172+
style::value(process.r#type.to_string()),
173+
process.command.join(" ")
174+
));
175+
}
176+
log_bullet = if Path::exists(&context.app_dir.join("Procfile")) {
177+
log_bullet
178+
.sub_bullet("Procfile detected")
179+
.sub_bullet("Skipping process type registration (add process types to your Procfile as needed)")
180+
} else {
181+
launch_builder.processes(processes);
182+
log_bullet
183+
.sub_bullet("No Procfile detected")
184+
.sub_bullet("Registering detected process types as launch processes")
185+
};
186+
log_bullet.done()
176187
}
177-
log_bullet.done()
178188
}
179189
Err(error) => log_launch_process_detection_warning(error, log_bullet),
180190
};

buildpacks/dotnet/tests/dotnet_publish_test.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,64 @@ fn test_dotnet_publish_with_debug_configuration() {
8383
);
8484
}
8585

86+
#[test]
87+
#[ignore = "integration test"]
88+
fn test_dotnet_publish_process_registration_with_procfile() {
89+
TestRunner::default().build(
90+
default_build_config("tests/fixtures/basic_web_9.0_with_procfile"),
91+
|context| {
92+
assert_empty!(context.pack_stderr);
93+
assert_contains!(
94+
&context.pack_stdout,
95+
indoc! { r"
96+
- Process types
97+
- Detecting process types from published artifacts
98+
- Found `foo`: bash -c cd bin/publish; ./foo --urls http://*:$PORT
99+
- Procfile detected
100+
- Skipping process type registration (add process types to your Procfile as needed)"}
101+
);
102+
},
103+
);
104+
}
105+
106+
#[test]
107+
#[ignore = "integration test"]
108+
fn test_dotnet_publish_process_registration_without_procfile() {
109+
TestRunner::default().build(
110+
default_build_config("tests/fixtures/basic_web_9.0"),
111+
|context| {
112+
assert_empty!(context.pack_stderr);
113+
assert_contains!(
114+
&context.pack_stdout,
115+
indoc! { r"
116+
- Process types
117+
- Detecting process types from published artifacts
118+
- Found `foo`: bash -c cd bin/publish; ./foo --urls http://*:$PORT
119+
- No Procfile detected
120+
- Registering detected process types as launch processes"}
121+
);
122+
},
123+
);
124+
}
125+
126+
#[test]
127+
#[ignore = "integration test"]
128+
fn test_dotnet_publish_process_registration_without_process_types() {
129+
TestRunner::default().build(
130+
default_build_config("tests/fixtures/class_library"),
131+
|context| {
132+
assert_empty!(context.pack_stderr);
133+
assert_contains!(
134+
&context.pack_stdout,
135+
indoc! { r"
136+
- Process types
137+
- Detecting process types from published artifacts
138+
- No processes were detected"}
139+
);
140+
},
141+
);
142+
}
143+
86144
#[test]
87145
#[ignore = "integration test"]
88146
fn test_dotnet_publish_with_global_json_and_custom_verbosity_level() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: foo
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var builder = WebApplication.CreateBuilder(args);
2+
var app = builder.Build();
3+
4+
app.MapGet("/", () => "Hello World!");
5+
6+
app.Run();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
10+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace class_library;
2+
3+
public class Class1
4+
{
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)