feat: support wildcard in ignored_containers (#666)
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -2417,6 +2417,7 @@ dependencies = [
|
|||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"which",
|
"which",
|
||||||
|
"wildmatch",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2712,6 +2713,12 @@ version = "0.4.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
|
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wildmatch"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "495ec47bf3c1345005f40724f0269362c8556cbc43aed0526ed44cae1d35fceb"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ tracing-subscriber = { version = "~0.3", features = ["env-filter", "time"] }
|
|||||||
merge = "~0.1"
|
merge = "~0.1"
|
||||||
regex-split = "~0.1"
|
regex-split = "~0.1"
|
||||||
notify-rust = "~4.10"
|
notify-rust = "~4.10"
|
||||||
|
wildmatch = "2.3.0"
|
||||||
|
|
||||||
[package.metadata.generate-rpm]
|
[package.metadata.generate-rpm]
|
||||||
assets = [{ source = "target/release/topgrade", dest = "/usr/bin/topgrade" }]
|
assets = [{ source = "target/release/topgrade", dest = "/usr/bin/topgrade" }]
|
||||||
|
|||||||
@@ -229,4 +229,5 @@
|
|||||||
|
|
||||||
# containers = ["archlinux-latest"]
|
# containers = ["archlinux-latest"]
|
||||||
[containers]
|
[containers]
|
||||||
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest"]
|
# Specify the containers to ignore while updating (Wildcard supported)
|
||||||
|
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest", "docker.io*"]
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use color_eyre::eyre::eyre;
|
|||||||
use color_eyre::eyre::Context;
|
use color_eyre::eyre::Context;
|
||||||
use color_eyre::eyre::Result;
|
use color_eyre::eyre::Result;
|
||||||
use tracing::{debug, error, warn};
|
use tracing::{debug, error, warn};
|
||||||
|
use wildmatch::WildMatch;
|
||||||
|
|
||||||
use crate::command::CommandExt;
|
use crate::command::CommandExt;
|
||||||
use crate::error::{self, TopgradeError};
|
use crate::error::{self, TopgradeError};
|
||||||
@@ -51,6 +52,13 @@ impl Display for Container {
|
|||||||
///
|
///
|
||||||
/// Containers specified in `ignored_containers` will be filtered out.
|
/// Containers specified in `ignored_containers` will be filtered out.
|
||||||
fn list_containers(crt: &Path, ignored_containers: Option<&Vec<String>>) -> Result<Vec<Container>> {
|
fn list_containers(crt: &Path, ignored_containers: Option<&Vec<String>>) -> Result<Vec<Container>> {
|
||||||
|
let ignored_containers = ignored_containers.map(|patterns| {
|
||||||
|
patterns
|
||||||
|
.iter()
|
||||||
|
.map(|pattern| WildMatch::new(pattern))
|
||||||
|
.collect::<Vec<WildMatch>>()
|
||||||
|
});
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Querying '{} image ls --format \"{{{{.Repository}}}}:{{{{.Tag}}}}/{{{{.ID}}}}\"' for containers",
|
"Querying '{} image ls --format \"{{{{.Repository}}}}:{{{{.Tag}}}}/{{{{.ID}}}}\"' for containers",
|
||||||
crt.display()
|
crt.display()
|
||||||
@@ -85,11 +93,8 @@ fn list_containers(crt: &Path, ignored_containers: Option<&Vec<String>>) -> Resu
|
|||||||
assert_eq!(split_res.len(), 2);
|
assert_eq!(split_res.len(), 2);
|
||||||
let (repo_tag, image_id) = (split_res[0], split_res[1]);
|
let (repo_tag, image_id) = (split_res[0], split_res[1]);
|
||||||
|
|
||||||
if let Some(ignored_containers) = ignored_containers {
|
if let Some(ref ignored_containers) = ignored_containers {
|
||||||
if ignored_containers
|
if ignored_containers.iter().any(|pattern| pattern.matches(repo_tag)) {
|
||||||
.iter()
|
|
||||||
.any(|ignored_container| repo_tag.eq(ignored_container))
|
|
||||||
{
|
|
||||||
debug!("Skipping ignored container '{}'", line);
|
debug!("Skipping ignored container '{}'", line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user