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
This commit is contained in:
Jack Wills
2022-09-05 08:31:01 -04:00
parent 832e9782d7
commit 1be9f52ad4
+14 -6
View File
@@ -1,6 +1,6 @@
use bollard::{ use bollard::{
container::{ListContainersOptions, LogsOptions, StartContainerOptions, Stats, StatsOptions}, container::{ListContainersOptions, LogsOptions, StartContainerOptions, Stats, StatsOptions},
Docker, Docker, service::ContainerSummary,
}; };
use futures_util::StreamExt; use futures_util::StreamExt;
use parking_lot::Mutex; 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 /// 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 /// 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)> { pub async fn update_all_containers(&mut self) -> Vec<(bool, String)> {
let containers = self let containers = self
.docker .docker
@@ -173,12 +174,19 @@ impl DockerData {
.await .await
.unwrap_or_default(); .unwrap_or_default();
let mut output = vec![]; let output = containers
// iter over containers, to only send ones which have an id, as use id for identification throughout!
containers
.iter() .iter()
.filter(|i| i.id.is_some()) .filter_map(|f| match f.id {
.for_each(|c| output.push(c.clone())); Some(_) => {
if f.command.as_ref().map_or(false, |c|c.contains("oxker")) {
None
} else {
Some(f.clone())
}
},
None => None,
})
.collect::<Vec<ContainerSummary>>();
self.app_data.lock().update_containers(&output); self.app_data.lock().update_containers(&output);