Skip to content

Commit

Permalink
feat: update_all_containers ignore oxker container
Browse files Browse the repository at this point in the history
filter_map over all container summaries, and ignore if the container command contains "oxker", for use when running oxker as a container itself
  • Loading branch information
mrjackwills committed Sep 5, 2022
1 parent 832e978 commit 1be9f52
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/docker_data/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bollard::{
container::{ListContainersOptions, LogsOptions, StartContainerOptions, Stats, StatsOptions},
Docker,
Docker, service::ContainerSummary,
};
use futures_util::StreamExt;
use parking_lot::Mutex;
Expand Down Expand Up @@ -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
Expand All @@ -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::<Vec<ContainerSummary>>();

self.app_data.lock().update_containers(&output);

Expand Down

0 comments on commit 1be9f52

Please # to comment.