Skip to content

Commit

Permalink
skopeo: add a helper method for inspecting a container image
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ondrejbudai committed Jan 16, 2024
1 parent aa4b811 commit 8122dd5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
22 changes: 22 additions & 0 deletions lib/src/skopeo.rs
Original file line number Diff line number Diff line change
@@ -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<String> {
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)
}

0 comments on commit 8122dd5

Please sign in to comment.