Skip to content

Commit

Permalink
feat: dump build command when --out is specified (railwayapp#1115)
Browse files Browse the repository at this point in the history
* feat: dump build command when --out is specified

the build command contains a lot of values which are generated from the nixpacks
build process. Without these dumped in the --out directory it's hard to debug
and replicate what's going on with a build.

* fmt

* fix static analysis error
  • Loading branch information
iloveitaly authored Jul 16, 2024
1 parent daf9d72 commit 9298f90
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/nixpacks/builder/docker/docker_image_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ fn get_output_dir(app_src: &str, options: &DockerBuilderOptions) -> Result<Outpu
}
}

fn command_to_string(command: &Command) -> String {
let args = command
.get_args()
.map(|arg| arg.to_string_lossy())
.collect::<Vec<_>>();
format!(
"{} {}",
command.get_program().to_string_lossy(),
args.join(" ")
)
}

use async_trait::async_trait;

#[async_trait]
Expand Down Expand Up @@ -78,10 +90,17 @@ impl ImageBuilder for DockerImageBuilder {
plan.write_supporting_files(&self.options, env, &output)
.context("Writing supporting files")?;

let mut docker_build_cmd = self.get_docker_build_cmd(plan, name.as_str(), &output)?;

if self.options.out_dir.is_some() {
let command_path = output.get_absolute_path("build.sh");
File::create(command_path.clone()).context("Creating command.sh file")?;
fs::write(command_path, command_to_string(&docker_build_cmd))
.context("Write command")?;
}

// Only build if the --out flag was not specified
if self.options.out_dir.is_none() {
let mut docker_build_cmd = self.get_docker_build_cmd(plan, name.as_str(), &output)?;

// Execute docker build
let build_result = docker_build_cmd.spawn()?.wait().context("Building image")?;
if !build_result.success() {
Expand Down

0 comments on commit 9298f90

Please sign in to comment.