Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable loading pre-pulled OCI artifact #1874

Merged
merged 1 commit into from
Oct 11, 2023
Merged
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
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