mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-17 17:43:37 -05:00
feat: add new filter for in use images to web ui
This commit is contained in:
16
src/check.rs
16
src/check.rs
@@ -3,7 +3,7 @@ use itertools::Itertools;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
||||
use crate::{
|
||||
docker::get_images_from_docker_daemon,
|
||||
docker::{get_images_from_docker_daemon, get_in_use_images},
|
||||
http::Client,
|
||||
registry::{check_auth, get_token},
|
||||
structs::{image::Image, update::Update},
|
||||
@@ -99,6 +99,15 @@ pub async fn get_updates(
|
||||
// Get local images
|
||||
ctx.logger.debug("Retrieving images to be checked");
|
||||
let mut images = get_images_from_docker_daemon(ctx, references).await;
|
||||
let in_use_images = get_in_use_images(ctx).await;
|
||||
ctx.logger.debug(format!("Found {} images in use", in_use_images.len()));
|
||||
|
||||
// Complete in_use field
|
||||
images.iter_mut().for_each(|image| {
|
||||
if in_use_images.contains(&image.reference) {
|
||||
image.in_use = true
|
||||
}
|
||||
});
|
||||
|
||||
// Add extra images from references
|
||||
if !all_references.is_empty() {
|
||||
@@ -195,7 +204,10 @@ pub async fn get_updates(
|
||||
}
|
||||
// Await all the futures
|
||||
let images = join_all(handles).await;
|
||||
let mut updates: Vec<Update> = images.iter().map(|image| image.to_update()).collect();
|
||||
let mut updates: Vec<Update> = images
|
||||
.iter()
|
||||
.map(|image| image.to_update())
|
||||
.collect();
|
||||
updates.extend_from_slice(&remote_updates);
|
||||
updates
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use bollard::{models::ImageInspect, ClientVersion, Docker};
|
||||
use bollard::{container::ListContainersOptions, models::ImageInspect, ClientVersion, Docker};
|
||||
|
||||
use futures::future::join_all;
|
||||
|
||||
@@ -94,3 +94,34 @@ pub async fn get_images_from_docker_daemon(
|
||||
local_images.append(&mut swarm_images);
|
||||
local_images
|
||||
}
|
||||
|
||||
pub async fn get_in_use_images(ctx: &Context) -> Vec<String> {
|
||||
let client: Docker = create_docker_client(ctx.config.socket.as_deref());
|
||||
|
||||
let containers = match client
|
||||
.list_containers::<String>(Some(ListContainersOptions {
|
||||
all: true,
|
||||
..Default::default()
|
||||
}))
|
||||
.await
|
||||
{
|
||||
Ok(containers) => containers,
|
||||
Err(e) => {
|
||||
error!("Failed to retrieve list of containers available!\n{}", e)
|
||||
}
|
||||
};
|
||||
|
||||
containers
|
||||
.iter()
|
||||
.filter_map(|container| match &container.image {
|
||||
Some(image) => Some({
|
||||
if image.contains(":") {
|
||||
image.clone()
|
||||
} else {
|
||||
format!("{image}:latest")
|
||||
}
|
||||
}),
|
||||
None => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ pub struct Image {
|
||||
pub url: Option<String>,
|
||||
pub digest_info: Option<DigestInfo>,
|
||||
pub version_info: Option<VersionInfo>,
|
||||
pub in_use: bool,
|
||||
pub error: Option<String>,
|
||||
pub time_ms: u32,
|
||||
}
|
||||
@@ -221,6 +222,7 @@ impl Image {
|
||||
},
|
||||
time: self.time_ms,
|
||||
server: None,
|
||||
in_use: self.in_use,
|
||||
status: has_update,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ pub struct Update {
|
||||
pub result: UpdateResult,
|
||||
pub time: u32,
|
||||
pub server: Option<String>,
|
||||
pub in_use: bool,
|
||||
#[serde(skip_serializing, skip_deserializing)]
|
||||
pub status: Status,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user