Skip to content

Commit

Permalink
build: add an flag to discard ephemeral container of failed builds
Browse files Browse the repository at this point in the history
  • Loading branch information
xtexx committed Dec 31, 2024
1 parent fc0daf1 commit 104ce8e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 5 additions & 1 deletion cli/src/actions/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ pub fn build_packages(args: &ArgMatches) -> Result<()> {
patch_instance_config(args, &mut config)?;
let inst = ws.ephemeral_container("build", config)?;
let result = ckpt.execute(&inst);
if result.is_err() {
if result.is_err() && !args.get_flag("always-discard") {
info!(
"{}: keeping ephemeral container for debug",
inst.as_ns_name()
);
_ = inst.leak();
} else {
inst.discard()?;
Expand Down
7 changes: 7 additions & 0 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ pub fn build_cli() -> Command {
.action(ArgAction::SetTrue)
.help("Select the starting point for a build"),
)
.arg(
Arg::new("always-discard")
.long("always-discard")
.action(ArgAction::SetTrue)
.conflicts_with("INSTANCE")
.help("Destory ephemeral containers if the build fails"),
)
.arg(Arg::new("PACKAGES").conflicts_with("resume").num_args(1..))
.about("Build the packages using the specified instance"),
)
Expand Down
8 changes: 6 additions & 2 deletions cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{

use anyhow::{bail, Result};
use indicatif::ProgressBar;
use nix::libc::{prctl, PR_GET_ENDIAN};
use sha2::{Digest, Sha256};
use unsquashfs_wrapper::Unsquashfs;

Expand Down Expand Up @@ -60,7 +59,12 @@ pub fn get_host_arch_name() -> Result<&'static str> {
#[cfg(target_arch = "powerpc64")]
{
let mut endian: nix::libc::c_int = -1;
let result = unsafe { prctl(PR_GET_ENDIAN, &mut endian as *mut nix::libc::c_int) };
let result = unsafe {
nix::libc::prctl(
nix::libc::PR_GET_ENDIAN,
&mut endian as *mut nix::libc::c_int,
)
};
if result < 0 {
bail!("Failed to get host endian");
}
Expand Down

0 comments on commit 104ce8e

Please sign in to comment.