Skip to content

Commit

Permalink
Merge pull request #1874 from jsturtevant/spin-oci
Browse files Browse the repository at this point in the history
Enable loading pre-pulled OCI artifact
  • Loading branch information
vdice authored Oct 11, 2023
2 parents 11ebf50 + 9287872 commit d84dde0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/oci/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl OciLoader {
Self { working_dir }
}

/// Loads a LockedApp with the given OCI client and reference.
/// Pulls and loads an OCI Artifact and returns a LockedApp with the given OCI client and reference
pub async fn load_app(&self, client: &mut Client, reference: &str) -> Result<LockedApp> {
// Fetch app
client.pull(reference).await.with_context(|| {
Expand All @@ -33,6 +33,17 @@ impl OciLoader {
.lockfile_path(&reference)
.await
.context("cannot get path to spin.lock")?;
self.load_from_cache(lockfile_path, reference, &client.cache)
.await
}

/// Loads an OCI Artifact from the given cache and returns a LockedApp with the given reference
pub async fn load_from_cache(
&self,
lockfile_path: PathBuf,
reference: &str,
cache: &Cache,
) -> std::result::Result<LockedApp, anyhow::Error> {
let locked_content = tokio::fs::read(&lockfile_path)
.await
.with_context(|| format!("failed to read from {lockfile_path:?}"))?;
Expand All @@ -47,7 +58,7 @@ impl OciLoader {
.insert("origin".to_string(), origin_uri.into());

for component in &mut locked_app.components {
self.resolve_component_content_refs(component, &client.cache)
self.resolve_component_content_refs(component, cache)
.await
.with_context(|| {
format!("failed to resolve content for component {:?}", component.id)
Expand Down

0 comments on commit d84dde0

Please sign in to comment.