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

Improve process registration logging #124

Merged
merged 3 commits into from
Aug 29, 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
1 change: 1 addition & 0 deletions buildpacks/dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- The buildpack log output now includes more launch process detection and registration details. ([#124](https://github.com/heroku/buildpacks-dotnet/pull/124))
- The `PublishDir` MSBuild property is now set to `bin/publish` when running `dotnet publish`, to ensure that the publish output for each project is consistently sent to the same location (relative to the project file). This enables writing `Procfile` commands that are compatible with any target OS/arch (i.e. Runtime Identifier (RID)), build configuration (e.g. `Release`/`Debug`) and Target Framework Moniker (TFM). ([#120](https://github.com/heroku/buildpacks-dotnet/pull/121))

## [0.1.1] - 2024-08-19
Expand Down
74 changes: 46 additions & 28 deletions buildpacks/dotnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::dotnet_buildpack_configuration::{
use crate::dotnet_publish_command::DotnetPublishCommand;
use crate::launch_process::LaunchProcessDetectionError;
use crate::layers::sdk::SdkLayerError;
use bullet_stream::state::Bullet;
use bullet_stream::state::{Bullet, SubBullet};
use bullet_stream::{style, Print};
use fun_run::CommandWithName;
use indoc::formatdoc;
Expand Down Expand Up @@ -66,6 +66,7 @@ impl Buildpack for DotnetBuildpack {
}
}

#[allow(clippy::too_many_lines)]
fn build(&self, context: BuildContext<Self>) -> libcnb::Result<BuildResult, Self::Error> {
let buildpack_configuration = DotnetBuildpackConfiguration::try_from(&Env::from_current())
.map_err(DotnetBuildpackError::ParseBuildpackConfiguration)?;
Expand Down Expand Up @@ -162,17 +163,32 @@ impl Buildpack for DotnetBuildpack {

layers::runtime::handle(&context, &sdk_layer.path())?;

let mut build_result_builder = BuildResultBuilder::new();
match launch_process::detect_solution_processes(&solution) {
log_bullet = log
.bullet("Setting launch table")
.sub_bullet("Detecting process types from published artifacts");
let mut launch_builder = LaunchBuilder::new();
log = match launch_process::detect_solution_processes(&solution) {
Ok(processes) => {
// TODO: Print log information about registered processes
build_result_builder =
build_result_builder.launch(LaunchBuilder::new().processes(processes).build());
if processes.is_empty() {
log_bullet = log_bullet.sub_bullet("No processes were detected");
}
for process in processes {
log_bullet = log_bullet.sub_bullet(format!(
"Added {}: {}",
style::value(process.r#type.to_string()),
process.command.join(" ")
));
launch_builder.process(process);
}
log_bullet.done()
}
Err(error) => log = log_launch_process_detection_warning(error, log),
}
Err(error) => log_launch_process_detection_warning(error, log_bullet),
};
log.done();
build_result_builder.build()

BuildResultBuilder::new()
.launch(launch_builder.build())
.build()
}

fn on_error(&self, error: libcnb::Error<Self::Error>) {
Expand Down Expand Up @@ -252,33 +268,35 @@ fn detect_global_json_sdk_version_requirement(

fn log_launch_process_detection_warning(
error: LaunchProcessDetectionError,
log: Print<Bullet<Stdout>>,
log: Print<SubBullet<Stdout>>,
) -> Print<Bullet<Stdout>> {
match error {
LaunchProcessDetectionError::ProcessType(process_type_error) => log.warning(formatdoc! {"
{process_type_error}
LaunchProcessDetectionError::ProcessType(process_type_error) => log
.warning(formatdoc! {"
{process_type_error}

Launch process detection error
Launch process detection error

We detected an invalid launch process type.
We detected an invalid launch process type.

The buildpack automatically tries to register Cloud Native Buildpacks (CNB)
process types for console and web projects after successfully publishing an
application.
The buildpack automatically tries to register Cloud Native Buildpacks (CNB)
process types for console and web projects after successfully publishing an
application.

Process type names are based on the filenames of compiled project executables,
which is usually the project name. For example, `webapi` for a `webapi.csproj`
project. In some cases, these names are be incompatible with the CNB spec as
process types can only contain numbers, letters, and the characters `.`, `_`,
and `-`.
Process type names are based on the filenames of compiled project executables,
which is usually the project name. For example, `webapi` for a `webapi.csproj`
project. In some cases, these names are be incompatible with the CNB spec as
process types can only contain numbers, letters, and the characters `.`, `_`,
and `-`.

To use this automatic launch process type registration, see the warning details
above to troubleshoot and make necessary adjustments.
To use this automatic launch process type registration, see the warning details
above to troubleshoot and make necessary adjustments.

If you think you found a bug in the buildpack, or have feedback on improving
the behavior for your use case, file an issue here:
https://github.com/heroku/buildpacks-dotnet/issues/new
"}),
If you think you found a bug in the buildpack, or have feedback on improving
the behavior for your use case, file an issue here:
https://github.com/heroku/buildpacks-dotnet/issues/new
"})
.done(),
}
}

Expand Down