Skip to content

Commit

Permalink
Merge pull request containers#560 from cgwalters/image-inspect
Browse files Browse the repository at this point in the history
cli: Add commands to output manifest and config
  • Loading branch information
cgwalters authored Nov 2, 2023
2 parents 26de776 + c7905fb commit e6951f7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ci/priv-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ostree-ext-cli container image prune-images --sysroot "${sysroot}"
ostree-ext-cli container image deploy --sysroot "${sysroot}" \
--stateroot "${stateroot}" --imgref "${imgref}"
ostree admin --sysroot="${sysroot}" status
ostree-ext-cli container image metadata --repo "${sysroot}/ostree/repo" registry:"${image}" > manifest.json
jq '.schemaVersion' < manifest.json
ostree-ext-cli container image remove --repo "${sysroot}/ostree/repo" registry:"${image}"
ostree admin --sysroot="${sysroot}" undeploy 0
# Now test the new syntax which has a nicer --image that defaults to registry.
Expand Down
38 changes: 37 additions & 1 deletion lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ostree::{gio, glib};
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::ffi::OsString;
use std::io::BufWriter;
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::process::Command;
use tokio::sync::mpsc::Receiver;
Expand Down Expand Up @@ -241,6 +241,21 @@ pub(crate) enum ContainerImageOpts {
imgref: ImageReference,
},

/// Output manifest or configuration for an already stored container image.
Metadata {
/// Path to the repository
#[clap(long, value_parser)]
repo: Utf8PathBuf,

/// Container image reference, e.g. registry:quay.io/exampleos/exampleos:latest
#[clap(value_parser = parse_base_imgref)]
imgref: ImageReference,

/// Output the config, not the manifest
#[clap(long)]
config: bool,
},

/// Copy a pulled container image from one repo to another.
Copy {
/// Path to the source repository
Expand Down Expand Up @@ -929,6 +944,27 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
let repo = parse_repo(&repo)?;
container_history(&repo, &imgref).await
}
ContainerImageOpts::Metadata {
repo,
imgref,
config,
} => {
let repo = parse_repo(&repo)?;
let image = crate::container::store::query_image_ref(&repo, &imgref)?
.ok_or_else(|| anyhow::anyhow!("No such image"))?;
let stdout = std::io::stdout().lock();
let mut stdout = std::io::BufWriter::new(stdout);
if config {
let config = image
.configuration
.ok_or_else(|| anyhow::anyhow!("Missing configuration"))?;
serde_json::to_writer(&mut stdout, &config)?;
} else {
serde_json::to_writer(&mut stdout, &image.manifest)?;
}
stdout.flush()?;
Ok(())
}
ContainerImageOpts::Remove {
repo,
imgrefs,
Expand Down

0 comments on commit e6951f7

Please sign in to comment.