Skip to content

Commit dc2709b

Browse files
authored
fix docker image validation on macos (#75)
1 parent 83a2828 commit dc2709b

2 files changed

Lines changed: 34 additions & 8 deletions

File tree

coman/src/cscs/handlers.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -859,12 +859,20 @@ pub async fn cscs_job_start(
859859
None
860860
};
861861
let image_meta = if let Some(docker_image) = docker_image {
862-
match docker_image.inspect().await {
863-
Ok(meta) => Some(meta),
864-
Err(e) => {
865-
println!("couldn't get image information: {e:?}");
866-
None
862+
if let Some(system_info) = config.values.cscs.systems.get(current_system) {
863+
let mut meta = None;
864+
for arch in system_info.architecture.iter() {
865+
if let Ok(img_meta) = docker_image.inspect(arch).await {
866+
meta = Some(img_meta);
867+
break;
868+
}
867869
}
870+
if meta.is_none() {
871+
println!("couldn't get image information, skipping checks");
872+
}
873+
meta
874+
} else {
875+
None
868876
}
869877
} else {
870878
None

coman/src/util/types.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use oci_client::{
1616
Client, Reference,
1717
client::{ClientConfig, ClientProtocol},
1818
config::ConfigFile,
19-
manifest::OciManifest,
19+
manifest::{ImageIndexEntry, OciManifest},
2020
secrets::RegistryAuth,
2121
};
22-
use oci_spec::image::Arch;
22+
use oci_spec::image::{Arch, Os};
2323

2424
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, strum::Display)]
2525
pub enum OciPlatform {
@@ -79,9 +79,27 @@ impl DockerImageUrl {
7979
)
8080
}
8181

82-
pub async fn inspect(&self) -> Result<DockerImageMeta> {
82+
pub async fn inspect(&self, arch: &str) -> Result<DockerImageMeta> {
83+
let arch = match arch {
84+
"arm64" => Arch::ARM64,
85+
"amd64" => Arch::Amd64,
86+
_ => {
87+
return Err(eyre!("unsupported architecture {}", arch));
88+
}
89+
};
8390
let client = Client::new(ClientConfig {
8491
protocol: ClientProtocol::Https,
92+
platform_resolver: Some(Box::new(move |manifests: &[ImageIndexEntry]| {
93+
manifests
94+
.iter()
95+
.find(|entry| {
96+
entry
97+
.platform
98+
.as_ref()
99+
.is_some_and(|platform| platform.os == Os::Linux && platform.architecture == arch)
100+
})
101+
.map(|entry| entry.digest.clone())
102+
})),
85103
..Default::default()
86104
});
87105
let reference = self.to_string().parse()?;

0 commit comments

Comments
 (0)