feat(containers): add option to run system prune (#1523)
Co-authored-by: Gideon <87426140+GideonBear@users.noreply.github.com>
This commit is contained in:
@@ -342,6 +342,10 @@
|
|||||||
# Specify the runtime to use for containers (default: "docker", allowed values: "docker", "podman")
|
# Specify the runtime to use for containers (default: "docker", allowed values: "docker", "podman")
|
||||||
# runtime = "podman"
|
# runtime = "podman"
|
||||||
|
|
||||||
|
# Run 'docker system prune' to clean up unused containers, networks, and build cache
|
||||||
|
# (default: false)
|
||||||
|
# system_prune = false
|
||||||
|
|
||||||
[lensfun]
|
[lensfun]
|
||||||
# If disabled, Topgrade invokes `lensfun‑update‑data` without root privilege,
|
# If disabled, Topgrade invokes `lensfun‑update‑data` without root privilege,
|
||||||
# then the update will be only available to you. Otherwise, `sudo` is required,
|
# then the update will be only available to you. Otherwise, `sudo` is required,
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ pub struct Containers {
|
|||||||
#[merge(strategy = crate::utils::merge_strategies::vec_prepend_opt)]
|
#[merge(strategy = crate::utils::merge_strategies::vec_prepend_opt)]
|
||||||
ignored_containers: Option<Vec<String>>,
|
ignored_containers: Option<Vec<String>>,
|
||||||
runtime: Option<ContainerRuntime>,
|
runtime: Option<ContainerRuntime>,
|
||||||
|
system_prune: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, Debug, Merge)]
|
#[derive(Deserialize, Default, Debug, Merge)]
|
||||||
@@ -958,6 +959,15 @@ impl Config {
|
|||||||
.unwrap_or(ContainerRuntime::Docker) // defaults to a popular choice
|
.unwrap_or(ContainerRuntime::Docker) // defaults to a popular choice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether to run system prune for containers.
|
||||||
|
pub fn containers_system_prune(&self) -> bool {
|
||||||
|
self.config_file
|
||||||
|
.containers
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|containers| containers.system_prune)
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
/// Tell whether the specified step should run.
|
/// Tell whether the specified step should run.
|
||||||
///
|
///
|
||||||
/// If the step appears either in the `--disable` command line argument
|
/// If the step appears either in the `--disable` command line argument
|
||||||
|
|||||||
@@ -224,7 +224,14 @@ pub fn run_containers(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.config().cleanup() {
|
if ctx.config().containers_system_prune() {
|
||||||
|
// Run system prune to clean up unused containers, networks, and build cache
|
||||||
|
if let Err(e) = ctx.execute(&crt).args(["system", "prune", "--force"]).status_checked() {
|
||||||
|
error!("Running system prune failed: {}", e);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
// Only run `image prune` if we don't run `system prune`
|
||||||
|
} else if ctx.config().cleanup() {
|
||||||
// Remove dangling images
|
// Remove dangling images
|
||||||
debug!("Removing dangling images");
|
debug!("Removing dangling images");
|
||||||
if let Err(e) = ctx.execute(&crt).args(["image", "prune", "-f"]).status_checked() {
|
if let Err(e) = ctx.execute(&crt).args(["image", "prune", "-f"]).status_checked() {
|
||||||
|
|||||||
Reference in New Issue
Block a user