From 8122dd5c6384fdcdbdb07bef4157c4b59a738889 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Budai?= Date: Wed, 13 Dec 2023 17:23:52 +0100 Subject: [PATCH] skopeo: add a helper method for inspecting a container image MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is basically the same thing as in podman.rs, just for skopeo (and without escaping the mount namespace). Signed-off-by: Ondřej Budai --- lib/src/lib.rs | 2 ++ lib/src/skopeo.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lib/src/skopeo.rs diff --git a/lib/src/lib.rs b/lib/src/lib.rs index fafdd991e..102347991 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -42,6 +42,8 @@ mod k8sapitypes; pub(crate) mod mount; #[cfg(feature = "install")] mod podman; +#[cfg(feature = "install")] +mod skopeo; pub mod spec; #[cfg(feature = "docgen")] diff --git a/lib/src/skopeo.rs b/lib/src/skopeo.rs new file mode 100644 index 000000000..ea95d6d79 --- /dev/null +++ b/lib/src/skopeo.rs @@ -0,0 +1,22 @@ +use std::process::Command; +use anyhow::Result; +use serde::Deserialize; + +#[derive(Deserialize)] +#[serde(rename_all = "PascalCase")] +pub(crate) struct Inspect { + pub(crate) digest: String, +} + +/// Given an image ID, return its manifest digest +pub(crate) fn oci_archive_digest(imageref: &str) -> Result { + let o = Command::new("skopeo") + .args(["inspect", imageref]) + .output().expect("running skopeo"); + let st = o.status; + if !st.success() { + anyhow::bail!("Failed to execute skopeo inspect: {st:?}"); + } + let i: Inspect = serde_json::from_slice(&o.stdout)?; + Ok(i.digest) +}