spin icon indicating copy to clipboard operation
spin copied to clipboard

Virtual file system for Spin components

Open radu-matei opened this issue 3 years ago • 1 comments

Currently in Spin, if a component declares a files field in its manifest, depending on the intended command, the following takes place:

  • for up when referencing a local spin.toml manifest file, all files (and patterns for directories) are copied into a temporary directory, and those temporary directories are mounted inside the WebAssembly module at runtime through WASI. https://github.com/fermyon/spin/blob/14603bb71f9592fbfe3d10f5deb961fddb89f58c/crates/loader/src/local/assets.rs#L13-L33

  • for publishing to Bindle (spin bindle push), the actual WebAssembly module and all files referenced in files are published into a bindle (each static asset is an individual parcel in the bindle). Then, when running from a Bindle reference (spin up --bindle), the static assets are copied into temporary directories, and those are mounted inside the WebAssembly module at runtime through WASI (same operation as when running locally, but the source of the files is from the remote bindle). https://github.com/fermyon/spin/blob/14603bb71f9592fbfe3d10f5deb961fddb89f58c/crates/loader/src/bindle/assets.rs#L35-L52

I would like to propose a third implementation for handling static assets in Spin — implementing a virtual file system for WASI. Specifically, this would mean that at runtime, instead of having to mount a directory from the host inside the WebAssembly module, all static assets could be dynamically read from WebAssembly data sections.

Thinking about how this could impact the distribution of Spin components, we could explore distributing a "self-contained" Wasm binary that already bundles all of its static assets into data sections. However, there is a main apparent disadvantage to doing so — if N Spin components need the same static asset, this approach would mean duplicating that asset N times (potentially across multiple versions of the same component, where that asset would be unmodified).

TL; DR — I would like to propose a virtual file system implementation for Spin static assets that would allow us to avoid mounting any host directories inside Wasm modules.

ref: https://github.com/kateinoigakukun/wasi-vfs

radu-matei avatar Apr 18 '22 11:04 radu-matei

The .NET WASI SDK does this (e.g. with the IL assemblies) and it makes for very convenient deployments!

itowlson avatar Apr 19 '22 01:04 itowlson