feat(prune)!: Create prune command

This commit is contained in:
Gerald Pinder 2024-11-27 14:00:49 -05:00
parent 879dca348c
commit 1671ea2143
13 changed files with 356 additions and 70 deletions

View file

@ -24,8 +24,13 @@ pub struct BuildahDriver;
impl DriverVersion for BuildahDriver {
// RUN mounts for bind, cache, and tmpfs first supported in 1.24.0
// https://buildah.io/releases/#changes-for-v1240
#[cfg(not(feature = "prune"))]
const VERSION_REQ: &'static str = ">=1.24";
// The prune command wasn't present until 1.29
#[cfg(feature = "prune")]
const VERSION_REQ: &'static str = ">=1.29";
fn version() -> Result<Version> {
trace!("BuildahDriver::version()");
@ -64,7 +69,7 @@ impl BuildDriver for BuildahDriver {
trace!("{command:?}");
let status = command
.status_image_ref_progress(&opts.image, "Building Image")
.build_status(&opts.image, "Building Image")
.into_diagnostic()?;
if status.success() {
@ -104,7 +109,7 @@ impl BuildDriver for BuildahDriver {
trace!("{command:?}");
let status = command
.status_image_ref_progress(&opts.image, "Pushing Image")
.build_status(&opts.image, "Pushing Image")
.into_diagnostic()?;
if status.success() {
@ -159,4 +164,24 @@ impl BuildDriver for BuildahDriver {
}
Ok(())
}
#[cfg(feature = "prune")]
fn prune(opts: &super::opts::PruneOpts) -> Result<()> {
trace!("PodmanDriver::prune({opts:?})");
let status = cmd!(
"buildah",
"prune",
"--force",
if opts.all => "-all",
)
.message_status("buildah prune", "Pruning Buildah System")
.into_diagnostic()?;
if !status.success() {
bail!("Failed to prune buildah");
}
Ok(())
}
}