m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-16 00:53:47 -05:00

fix: ignore invalid digests instead of panicking

This commit is contained in:
Sergio
2025-03-16 18:40:10 +02:00
parent e965380133
commit c411fc4bad
2 changed files with 16 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ pub async fn get_images_from_docker_daemon(
Some(service_spec) => match &service_spec.task_template { Some(service_spec) => match &service_spec.task_template {
Some(task_spec) => match &task_spec.container_spec { Some(task_spec) => match &task_spec.container_spec {
Some(container_spec) => match &container_spec.image { Some(container_spec) => match &container_spec.image {
Some(image) => Image::from_inspect_data(image), Some(image) => Image::from_inspect_data(ctx, image),
None => None, None => None,
}, },
None => None, None => None,
@@ -75,7 +75,7 @@ pub async fn get_images_from_docker_daemon(
.collect(); .collect();
inspects inspects
.iter() .iter()
.filter_map(|inspect| Image::from_inspect_data(inspect.clone())) .filter_map(|inspect| Image::from_inspect_data(ctx, inspect.clone()))
.collect() .collect()
} }
None => { None => {
@@ -87,7 +87,7 @@ pub async fn get_images_from_docker_daemon(
}; };
images images
.iter() .iter()
.filter_map(|image| Image::from_inspect_data(image.clone())) .filter_map(|image| Image::from_inspect_data(ctx, image.clone()))
.collect::<Vec<Image>>() .collect::<Vec<Image>>()
} }
}; };

View File

@@ -44,7 +44,7 @@ pub struct Image {
impl Image { impl Image {
/// Creates and populates the fields of an Image object based on the ImageSummary from the Docker daemon /// Creates and populates the fields of an Image object based on the ImageSummary from the Docker daemon
pub fn from_inspect_data<T: InspectData>(image: T) -> Option<Self> { pub fn from_inspect_data<T: InspectData>(ctx: &Context, image: T) -> Option<Self> {
let tags = image.tags().unwrap(); let tags = image.tags().unwrap();
let digests = image.digests().unwrap(); let digests = image.digests().unwrap();
if !tags.is_empty() && !digests.is_empty() { if !tags.is_empty() && !digests.is_empty() {
@@ -56,7 +56,18 @@ impl Image {
let version_tag = Version::from_tag(&tag); let version_tag = Version::from_tag(&tag);
let local_digests = digests let local_digests = digests
.iter() .iter()
.map(|digest| digest.split('@').collect::<Vec<&str>>()[1].to_string()) .filter_map(
|digest| match digest.split('@').collect::<Vec<&str>>().get(1) {
Some(digest) => Some(digest.to_string()),
None => {
ctx.logger.warn(format!(
"Ignoring invalid digest {} for image {}!",
digest, reference
));
None
}
},
)
.collect(); .collect();
Some(Self { Some(Self {
reference, reference,