deb: fix runtime usage for chroot
Some checks failed
CI / build (push) Failing after 2m3s

This commit is contained in:
2026-01-26 10:09:02 +01:00
parent c3a116203a
commit 0f9005d920
3 changed files with 14 additions and 12 deletions

View File

@@ -17,7 +17,7 @@ pub struct EphemeralContextGuard {
impl EphemeralContextGuard {
/// Create a new ephemeral unshare context for the specified series
pub fn new(series: &str) -> Result<Self, Box<dyn Error>> {
pub async fn new(series: &str) -> Result<Self, Box<dyn Error>> {
let current_context_name = context::manager().current_name();
// Create a temporary directory for the chroot
@@ -31,7 +31,7 @@ impl EphemeralContextGuard {
);
// Download and extract the chroot tarball
Self::download_and_extract_chroot(series, &chroot_path)?;
Self::download_and_extract_chroot(series, &chroot_path).await?;
// Switch to an ephemeral context to build the package in the chroot
context::manager().set_current_ephemeral(Context::new(ContextConfig::Unshare {
@@ -46,7 +46,7 @@ impl EphemeralContextGuard {
})
}
fn download_and_extract_chroot(
async fn download_and_extract_chroot(
series: &str,
chroot_path: &PathBuf,
) -> Result<(), Box<dyn Error>> {
@@ -95,7 +95,7 @@ impl EphemeralContextGuard {
// Download tarball if it doesn't exist
if !tarball_path.exists() {
log::debug!("Downloading chroot tarball for {}...", series);
Self::download_chroot_tarball(series, &tarball_path)?;
Self::download_chroot_tarball(series, &tarball_path).await?;
} else {
log::debug!("Using cached chroot tarball for {}", series);
}
@@ -111,7 +111,10 @@ impl EphemeralContextGuard {
Ok(())
}
fn download_chroot_tarball(series: &str, tarball_path: &Path) -> Result<(), Box<dyn Error>> {
async fn download_chroot_tarball(
series: &str,
tarball_path: &Path,
) -> Result<(), Box<dyn Error>> {
let ctx = context::current();
// Create a lock file to make sure that noone tries to use the file while it's not fully downloaded
@@ -121,9 +124,7 @@ impl EphemeralContextGuard {
.status()?;
// Make sure we have the right apt keyrings to mmdebstrap the chroot
tokio::runtime::Runtime::new().unwrap().block_on(
crate::apt::keyring::download_trust_keyring(Some(ctx.clone()), series),
)?;
crate::apt::keyring::download_trust_keyring(Some(ctx.clone()), series).await?;
// Use mmdebstrap to download the tarball to the cache directory
let status = ctx

View File

@@ -17,7 +17,7 @@ pub enum BuildMode {
}
/// Build package in 'cwd' to a .deb
pub fn build_binary_package(
pub async fn build_binary_package(
arch: Option<&str>,
series: Option<&str>,
cwd: Option<&Path>,
@@ -49,7 +49,7 @@ pub fn build_binary_package(
// Create an ephemeral unshare context for all Local builds
let mut guard = if mode == BuildMode::Local {
Some(ephemeral::EphemeralContextGuard::new(series)?)
Some(ephemeral::EphemeralContextGuard::new(series).await?)
} else {
None
};

View File

@@ -157,9 +157,10 @@ fn main() {
_ => None,
};
if let Err(e) =
if let Err(e) = rt.block_on(async {
pkh::deb::build_binary_package(arch, series, Some(cwd.as_path()), *cross, mode)
{
.await
}) {
error!("{}", e);
std::process::exit(1);
}