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

Allow hosts to control local loader download cache #2095

Merged
merged 1 commit into from
Nov 14, 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
3 changes: 2 additions & 1 deletion crates/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ pub(crate) const MAX_FILE_LOADING_CONCURRENCY: usize = 16;
pub async fn from_file(
manifest_path: impl AsRef<Path>,
files_mount_strategy: FilesMountStrategy,
cache_root: Option<PathBuf>,
) -> Result<LockedApp> {
let path = manifest_path.as_ref();
let app_root = parent_dir(path)?;
let loader = LocalLoader::new(&app_root, files_mount_strategy).await?;
let loader = LocalLoader::new(&app_root, files_mount_strategy, cache_root).await?;
loader.load_file(path).await
}

Expand Down
8 changes: 6 additions & 2 deletions crates/loader/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ pub struct LocalLoader {
}

impl LocalLoader {
pub async fn new(app_root: &Path, files_mount_strategy: FilesMountStrategy) -> Result<Self> {
pub async fn new(
app_root: &Path,
files_mount_strategy: FilesMountStrategy,
cache_root: Option<PathBuf>,
) -> Result<Self> {
let app_root = app_root
.canonicalize()
.with_context(|| format!("Invalid manifest dir `{}`", app_root.display()))?;
Ok(Self {
app_root,
files_mount_strategy,
cache: Cache::new(None).await?,
cache: Cache::new(cache_root).await?,
// Limit concurrency to avoid hitting system resource limits
file_loading_permits: Semaphore::new(crate::MAX_FILE_LOADING_CONCURRENCY),
})
Expand Down
1 change: 1 addition & 0 deletions crates/loader/tests/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn run_test(input: &Path, normalizer: &mut Normalizer) -> Result<String, Failed>
let locked = spin_loader::from_file(
input,
spin_loader::FilesMountStrategy::Copy(files_mount_root),
None,
)
.await
.map_err(|err| format!("{err:?}"))?;
Expand Down
1 change: 1 addition & 0 deletions crates/oci/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Client {
let locked = spin_loader::from_file(
manifest_path,
FilesMountStrategy::Copy(working_dir.path().into()),
None,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion src/commands/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl UpCommand {
} else {
FilesMountStrategy::Copy(working_dir.join("assets"))
};
spin_loader::from_file(&manifest_path, files_mount_strategy)
spin_loader::from_file(&manifest_path, files_mount_strategy, None)
.await
.with_context(|| format!("Failed to load manifest from {manifest_path:?}"))
}
Expand Down
Loading