Skip to content

Commit

Permalink
feat: add debug option to Docker build commands
Browse files Browse the repository at this point in the history
This would enable an interative shell to be opened up if a build fails. This is still experimental
and I'm running into some issues using this with orbstack, so this PR is still very much a WIP.

orbstack/orbstack#1700

Without this option, the only way to debug a failing build is to `--out` the build, insert multi-stage
build commands in the dockerfile and then use `--target` to get in-progress container ID to play around
with, which is super lame. We need a better way.
  • Loading branch information
iloveitaly committed Jan 7, 2025
1 parent 93176dc commit 40f51f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ enum Commands {
#[arg(long)]
docker_cert_path: Option<String>,

/// Open an interactive shell if the build fails
#[arg(long)]
debug: bool,

/// Enable writing cache metadata into the output image
#[arg(long)]
inline_cache: bool,
Expand Down
11 changes: 11 additions & 0 deletions src/nixpacks/builder/docker/docker_image_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ fn get_output_dir(app_src: &str, options: &DockerBuilderOptions) -> Result<Outpu
}
}

// TODO need to quote the output here otherwise the build command will fail with special char ENV vars

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(),
Expand Down Expand Up @@ -145,8 +148,16 @@ impl DockerImageBuilder {

// Enable BuildKit for all builds
docker_build_cmd.env("DOCKER_BUILDKIT", "1");

if self.options.debug {
docker_build_cmd.env("BUILDX_EXPERIMENTAL", "1");
}

docker_build_cmd
.arg("buildx")
.arg("debug")
.arg("--invoke")
.arg("bash")
.arg("build")
.arg(&output.root)
.arg("-f")
Expand Down
1 change: 1 addition & 0 deletions src/nixpacks/builder/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct DockerBuilderOptions {
pub cpu_quota: Option<String>,
pub memory: Option<String>,
pub verbose: bool,
pub debug: bool,
pub docker_host: Option<String>,
pub docker_tls_verify: Option<String>,
pub docker_output: Option<String>,
Expand Down

0 comments on commit 40f51f9

Please sign in to comment.