From 1be9f52ad4a68f93142784e9df630c59cdec0a79 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Mon, 5 Sep 2022 08:31:01 -0400 Subject: [PATCH] feat: update_all_containers ignore oxker container filter_map over all container summaries, and ignore if the container command contains "oxker", for use when running oxker as a container itself --- src/docker_data/mod.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 19019ba..c49182c 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -1,6 +1,6 @@ use bollard::{ container::{ListContainersOptions, LogsOptions, StartContainerOptions, Stats, StatsOptions}, - Docker, + Docker, service::ContainerSummary, }; use futures_util::StreamExt; use parking_lot::Mutex; @@ -163,6 +163,7 @@ impl DockerData { /// Get all current containers, handle into ContainerItem in the app_data struct rather than here /// Just make sure that items sent are guaranteed to have an id + /// Will ignore any container that uses `oxker` as an entry point pub async fn update_all_containers(&mut self) -> Vec<(bool, String)> { let containers = self .docker @@ -173,12 +174,19 @@ impl DockerData { .await .unwrap_or_default(); - let mut output = vec![]; - // iter over containers, to only send ones which have an id, as use id for identification throughout! - containers + let output = containers .iter() - .filter(|i| i.id.is_some()) - .for_each(|c| output.push(c.clone())); + .filter_map(|f| match f.id { + Some(_) => { + if f.command.as_ref().map_or(false, |c|c.contains("oxker")) { + None + } else { + Some(f.clone()) + } + }, + None => None, + }) + .collect::>(); self.app_data.lock().update_containers(&output);