Skip to content

Commit

Permalink
stream cmd stdout and stderr wip
Browse files Browse the repository at this point in the history
  • Loading branch information
angeldcampbell authored and mars committed Dec 12, 2024
1 parent a1f7cd2 commit 1849991
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions buildpacks/static-web-server/src/config_web_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use libcnb::{build::BuildContext, layer::UncachedLayerDefinition};
use libherokubuildpack::log::log_info;
use static_web_server_utils::read_project_config;
use std::fs;
use std::process::{Command, Output};
use std::process::{Child, Command, Stdio};
use toml::Table;

pub(crate) fn config_web_server(
Expand Down Expand Up @@ -40,25 +40,17 @@ pub(crate) fn config_web_server(
.map_err(StaticWebServerBuildpackError::CannotWriteCaddyConfiguration)?;

// Execute the optional build command
build_command_opt.map(|e| -> Result<Output, StaticWebServerBuildpackError> {
build_command_opt.map(|e| -> Result<Child, StaticWebServerBuildpackError> {
log_info(format!("Executing build command: {e:#?}"));
let mut cmd = Command::new(e.command.clone());
e.args.clone().map(|v| cmd.args(v));
let output = cmd
.output()
.map_err(StaticWebServerBuildpackError::BuildCommandFailed)?;

log_info(format!("status: {}", output.status));
log_info(format!(
"stdout: {}",
String::from_utf8_lossy(&output.stdout)
));
log_info(format!(
"stderr: {}",
String::from_utf8_lossy(&output.stderr)
));

Ok(output)
let mut cmd = Command::new(e.command);
if let Some(args) = e.args {
cmd.args(args);
}

cmd.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
.map_err(StaticWebServerBuildpackError::BuildCommandFailed)
});

Ok(configuration_layer)
Expand Down

0 comments on commit 1849991

Please sign in to comment.