Add option to ignore containers to pull (#613)
This commit is contained in:
@@ -223,3 +223,5 @@
|
|||||||
# use_root = false
|
# use_root = false
|
||||||
|
|
||||||
# containers = ["archlinux-latest"]
|
# containers = ["archlinux-latest"]
|
||||||
|
[containers]
|
||||||
|
# ignored_containers = ["ghcr.io/rancher-sandbox/rancher-desktop/rdx-proxy:latest"]
|
||||||
|
|||||||
@@ -159,6 +159,13 @@ pub struct Include {
|
|||||||
paths: Option<Vec<String>>,
|
paths: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default, Debug, Merge)]
|
||||||
|
#[serde(deny_unknown_fields)]
|
||||||
|
pub struct Containers {
|
||||||
|
#[merge(strategy = crate::utils::merge_strategies::vec_prepend_opt)]
|
||||||
|
ignored_containers: Option<Vec<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Default, Debug, Merge)]
|
#[derive(Deserialize, Default, Debug, Merge)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Git {
|
pub struct Git {
|
||||||
@@ -411,6 +418,9 @@ pub struct ConfigFile {
|
|||||||
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
||||||
git: Option<Git>,
|
git: Option<Git>,
|
||||||
|
|
||||||
|
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
||||||
|
containers: Option<Containers>,
|
||||||
|
|
||||||
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
#[merge(strategy = crate::utils::merge_strategies::inner_merge_opt)]
|
||||||
windows: Option<Windows>,
|
windows: Option<Windows>,
|
||||||
|
|
||||||
@@ -842,6 +852,14 @@ impl Config {
|
|||||||
self.config_file.git.as_ref().and_then(|git| git.repos.as_ref())
|
self.config_file.git.as_ref().and_then(|git| git.repos.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The list of docker/podman containers to ignore.
|
||||||
|
pub fn containers_ignored_tags(&self) -> Option<&Vec<String>> {
|
||||||
|
self.config_file
|
||||||
|
.containers
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|containers| containers.ignored_containers.as_ref())
|
||||||
|
}
|
||||||
|
|
||||||
/// 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
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ impl Display for Container {
|
|||||||
|
|
||||||
/// Returns a Vector of all containers, with Strings in the format
|
/// Returns a Vector of all containers, with Strings in the format
|
||||||
/// "REGISTRY/[PATH/]CONTAINER_NAME:TAG"
|
/// "REGISTRY/[PATH/]CONTAINER_NAME:TAG"
|
||||||
fn list_containers(crt: &Path) -> Result<Vec<Container>> {
|
///
|
||||||
|
/// Containers specified in `ignored_containers` will be filtered out.
|
||||||
|
fn list_containers(crt: &Path, ignored_containers: Option<&Vec<String>>) -> Result<Vec<Container>> {
|
||||||
debug!(
|
debug!(
|
||||||
"Querying '{} image ls --format \"{{{{.Repository}}}}:{{{{.Tag}}}}/{{{{.ID}}}}\"' for containers",
|
"Querying '{} image ls --format \"{{{{.Repository}}}}:{{{{.Tag}}}}/{{{{.ID}}}}\"' for containers",
|
||||||
crt.display()
|
crt.display()
|
||||||
@@ -83,6 +85,16 @@ fn list_containers(crt: &Path) -> Result<Vec<Container>> {
|
|||||||
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 ignored_containers
|
||||||
|
.iter()
|
||||||
|
.any(|ignored_container| repo_tag.eq(ignored_container))
|
||||||
|
{
|
||||||
|
debug!("Skipping ignored container '{}'", line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Querying '{} image inspect --format \"{{{{.Os}}}}/{{{{.Architecture}}}}\"' for container {}",
|
"Querying '{} image inspect --format \"{{{{.Os}}}}/{{{{.Architecture}}}}\"' for container {}",
|
||||||
crt.display(),
|
crt.display(),
|
||||||
@@ -109,7 +121,8 @@ pub fn run_containers(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
|
|
||||||
print_separator("Containers");
|
print_separator("Containers");
|
||||||
let mut success = true;
|
let mut success = true;
|
||||||
let containers = list_containers(&crt).context("Failed to list Docker containers")?;
|
let containers =
|
||||||
|
list_containers(&crt, ctx.config().containers_ignored_tags()).context("Failed to list Docker containers")?;
|
||||||
debug!("Containers to inspect: {:?}", containers);
|
debug!("Containers to inspect: {:?}", containers);
|
||||||
|
|
||||||
for container in containers.iter() {
|
for container in containers.iter() {
|
||||||
|
|||||||
Reference in New Issue
Block a user