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

Commit

Permalink
Merge pull request #552 from cgwalters/add-version-api
Browse files Browse the repository at this point in the history
lib/container: Add APIs to retrieve version conveniently
  • Loading branch information
jmarrero authored Oct 3, 2023
2 parents e435628 + c8545e1 commit e74e2f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit e74e2f9

Please sign in to comment.