This commit is contained in:
@@ -17,7 +17,7 @@ pub struct EphemeralContextGuard {
|
|||||||
|
|
||||||
impl EphemeralContextGuard {
|
impl EphemeralContextGuard {
|
||||||
/// Create a new ephemeral unshare context for the specified series
|
/// 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();
|
let current_context_name = context::manager().current_name();
|
||||||
|
|
||||||
// Create a temporary directory for the chroot
|
// Create a temporary directory for the chroot
|
||||||
@@ -31,7 +31,7 @@ impl EphemeralContextGuard {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Download and extract the chroot tarball
|
// 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
|
// Switch to an ephemeral context to build the package in the chroot
|
||||||
context::manager().set_current_ephemeral(Context::new(ContextConfig::Unshare {
|
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,
|
series: &str,
|
||||||
chroot_path: &PathBuf,
|
chroot_path: &PathBuf,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
@@ -95,7 +95,7 @@ impl EphemeralContextGuard {
|
|||||||
// Download tarball if it doesn't exist
|
// Download tarball if it doesn't exist
|
||||||
if !tarball_path.exists() {
|
if !tarball_path.exists() {
|
||||||
log::debug!("Downloading chroot tarball for {}...", series);
|
log::debug!("Downloading chroot tarball for {}...", series);
|
||||||
Self::download_chroot_tarball(series, &tarball_path)?;
|
Self::download_chroot_tarball(series, &tarball_path).await?;
|
||||||
} else {
|
} else {
|
||||||
log::debug!("Using cached chroot tarball for {}", series);
|
log::debug!("Using cached chroot tarball for {}", series);
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,10 @@ impl EphemeralContextGuard {
|
|||||||
Ok(())
|
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();
|
let ctx = context::current();
|
||||||
|
|
||||||
// Create a lock file to make sure that noone tries to use the file while it's not fully downloaded
|
// 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()?;
|
.status()?;
|
||||||
|
|
||||||
// Make sure we have the right apt keyrings to mmdebstrap the chroot
|
// 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).await?;
|
||||||
crate::apt::keyring::download_trust_keyring(Some(ctx.clone()), series),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// Use mmdebstrap to download the tarball to the cache directory
|
// Use mmdebstrap to download the tarball to the cache directory
|
||||||
let status = ctx
|
let status = ctx
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub enum BuildMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Build package in 'cwd' to a .deb
|
/// Build package in 'cwd' to a .deb
|
||||||
pub fn build_binary_package(
|
pub async fn build_binary_package(
|
||||||
arch: Option<&str>,
|
arch: Option<&str>,
|
||||||
series: Option<&str>,
|
series: Option<&str>,
|
||||||
cwd: Option<&Path>,
|
cwd: Option<&Path>,
|
||||||
@@ -49,7 +49,7 @@ pub fn build_binary_package(
|
|||||||
|
|
||||||
// Create an ephemeral unshare context for all Local builds
|
// Create an ephemeral unshare context for all Local builds
|
||||||
let mut guard = if mode == BuildMode::Local {
|
let mut guard = if mode == BuildMode::Local {
|
||||||
Some(ephemeral::EphemeralContextGuard::new(series)?)
|
Some(ephemeral::EphemeralContextGuard::new(series).await?)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -227,6 +227,7 @@ mod tests {
|
|||||||
|
|
||||||
log::info!("Starting binary package build...");
|
log::info!("Starting binary package build...");
|
||||||
crate::deb::build_binary_package(arch, Some(series), Some(&cwd), cross, None)
|
crate::deb::build_binary_package(arch, Some(series), Some(&cwd), cross, None)
|
||||||
|
.await
|
||||||
.expect("Cannot build binary package (deb)");
|
.expect("Cannot build binary package (deb)");
|
||||||
log::info!("Successfully built binary package");
|
log::info!("Successfully built binary package");
|
||||||
|
|
||||||
|
|||||||
@@ -157,9 +157,10 @@ fn main() {
|
|||||||
_ => None,
|
_ => 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)
|
pkh::deb::build_binary_package(arch, series, Some(cwd.as_path()), *cross, mode)
|
||||||
{
|
.await
|
||||||
|
}) {
|
||||||
error!("{}", e);
|
error!("{}", e);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user