From 928787247498607a2a1433d58fd621274a61ea26 Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Sat, 30 Sep 2023 02:19:26 +0000 Subject: [PATCH] enable loading pre-pulled OCI artifact Signed-off-by: James Sturtevant --- crates/oci/src/loader.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/oci/src/loader.rs b/crates/oci/src/loader.rs index 21856954a..3cb7c20ee 100644 --- a/crates/oci/src/loader.rs +++ b/crates/oci/src/loader.rs @@ -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 { // Fetch app client.pull(reference).await.with_context(|| { @@ -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 { let locked_content = tokio::fs::read(&lockfile_path) .await .with_context(|| format!("failed to read from {lockfile_path:?}"))?; @@ -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)