Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

lib/container: Add APIs to retrieve version conveniently #552

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/src/container/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ impl LayeredImageState {
self.base_commit.as_str()
}
}

/// Retrieve the container image version.
pub fn version(&self) -> Option<&str> {
self.configuration
.as_ref()
.and_then(super::version_for_config)
}
}

/// Locally cached metadata for an update to an existing image.
Expand All @@ -153,6 +160,13 @@ pub struct CachedImageUpdate {
pub manifest_digest: String,
}

impl CachedImageUpdate {
/// Retrieve the container image version.
pub fn version(&self) -> Option<&str> {
super::version_for_config(&self.config)
}
}

/// Context for importing a container image.
#[derive(Debug)]
pub struct ImageImporter {
Expand Down
8 changes: 5 additions & 3 deletions lib/tests/it/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,13 +780,15 @@ r usr/bin/bash bash-v0
{
let cached = store::query_image_ref(fixture.destrepo(), &imgref.imgref)
.unwrap()
.unwrap()
.cached_update
.unwrap();
assert_eq!(cached.version(), Some("42.0"));

let cached_update = cached.cached_update.unwrap();
assert_eq!(
cached.manifest_digest.as_str(),
cached_update.manifest_digest.as_str(),
prep.manifest_digest.as_str()
);
assert_eq!(cached_update.version(), Some("42.0"));
}
let to_fetch = prep.layers_to_fetch().collect::<Result<Vec<_>>>()?;
assert_eq!(to_fetch.len(), 2);
Expand Down
Loading