Skip to content

Commit aa85398

Browse files
committed
Unify image inspection
Doesn't make sense to fork skopeo for this. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent ebf2c08 commit aa85398

File tree

5 files changed

+175
-36
lines changed

5 files changed

+175
-36
lines changed

Cargo.lock

Lines changed: 167 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/kit/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ camino = "1.1.12"
4646
comfy-table = "7.1"
4747
strum = { version = "0.26", features = ["derive"] }
4848
quick-xml = "0.36"
49+
oci-spec = "0.8.2"
4950

5051
[dev-dependencies]
5152
similar-asserts = "1.5"

crates/kit/src/images.rs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ pub struct ImageInspect {
106106
/// SHA256 image identifier
107107
pub id: String,
108108

109+
/// Image digest
110+
pub digest: oci_spec::image::Digest,
111+
109112
/// Image size in bytes
110113
pub size: u64,
111114

@@ -232,35 +235,6 @@ pub fn get_image_size(name: &str) -> Result<u64> {
232235
Ok(info.size)
233236
}
234237

235-
/// Get container image digest (sha256) for caching purposes.
236-
/// Returns the digest in the format "sha256:abc123..."
237-
pub fn get_image_digest(name: &str) -> Result<String> {
238-
tracing::debug!("Getting digest for image: {}", name);
239-
240-
// Use skopeo inspect to get the manifest digest, which is more reliable than podman
241-
// for getting the actual @sha256 digest that can be used for caching
242-
let output = hostexec::command("skopeo", None)?
243-
.args(["inspect", &format!("containers-storage:{}", name)])
244-
.run_and_parse_json::<serde_json::Value>()
245-
.map_err(|e| eyre!("Failed to inspect image with skopeo: {}", e))?;
246-
247-
// Extract the digest from the skopeo output
248-
if let Some(digest) = output.get("Digest").and_then(|d| d.as_str()) {
249-
tracing::debug!("Found image digest: {}", digest);
250-
Ok(digest.to_string())
251-
} else {
252-
// Fall back to podman image inspect
253-
tracing::debug!("No digest in skopeo output, falling back to podman inspect");
254-
let info = inspect(name)?;
255-
// Podman ID is already in sha256:xxx format
256-
if info.id.starts_with("sha256:") {
257-
Ok(info.id)
258-
} else {
259-
Ok(format!("sha256:{}", info.id))
260-
}
261-
}
262-
}
263-
264238
#[cfg(test)]
265239
mod tests {
266240
use super::*;

crates/kit/src/libvirt/create.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ impl LibvirtCreateOpts {
200200
}
201201

202202
// It's a container image, check for cached volume
203-
let image_digest = images::get_image_digest(&self.volume_name_or_image)?;
203+
let image = images::inspect(&self.volume_name_or_image)?;
204+
let image_digest = image.digest.to_string();
204205

205206
if let Some(cached_volume) = self.find_cached_volume(global_opts, &image_digest)? {
206207
debug!("Using cached volume: {}", cached_volume);

crates/kit/src/libvirt/upload.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ pub fn run(global_opts: &crate::libvirt::LibvirtOptions, opts: LibvirtUploadOpts
188188
);
189189

190190
// Phase 1: Extract image digest for caching
191-
let image_digest = images::get_image_digest(&opts.source_image)?;
191+
let inspect = images::inspect(&opts.source_image)?;
192+
let image_digest = &inspect.digest.to_string();
192193
debug!("Container image digest: {}", image_digest);
193194

194195
// Phase 2: Calculate disk size to use

0 commit comments

Comments
 (0)