vmware-labs / wasm-workers-server

🚀 Develop and run serverless applications on WebAssembly
https://workers.wasmlabs.dev
Apache License 2.0
517 stars 35 forks source link

Allow to load a wasm file from a remote registry #121

Open k33g opened 1 year ago

k33g commented 1 year ago

Is your feature request related to a problem? Please describe.

I publish my wasm plugin on wapm.io or a GitLab Generic Package registry. At the start of wws I would like to be able to set an option or an environment variable with the URL of the wasm module to download the module and then start/serve it.

Describe the solution you'd like

wws \ 
--remote-location https://gitlab.com/api/v4/projects/${PROJECT_ID}/packages/generic/${PACKAGE}/${VERSION}/${MODULE}" \
--save-to ./hello

Describe alternatives you've considered

No response

Additional context

No response

Angelmmiguel commented 1 year ago

Hello @k33g!

Thank you for the issue and the suggestion 😄. To understand better the issue and solution, are those public registries exposing these resources following any specification like OCI? Are they just exposing the resources as files?

In the example, the download filename is hello. Wasm Workers Server relies on the file extension to identify the language runtime. Is the extension missed from the example or something related to the registries?

Thanks!

k33g commented 1 year ago

@Angelmmiguel Sorry I missed some details, in this case I would say ./hello would be a directory

I used the GitLab generic package registry so it's more exposing resources as files, but OCI would be nice too

Angelmmiguel commented 1 year ago

Thanks for the clarification! Yes, I agree it would be interesting support multiple remote artifacts. It reminds me how some JavaScript runtimes like Deno supports running remote scripts:

$ deno run https://deno.land/std/examples/welcome.ts
Welcome to Deno!

I would make these resources as valid paths for wws like:

wws https://example.com/index.js
wws oci://...

The protocol will determine how to handle it. I may need to give a thought about how to distinguish between scripts and compressed resources. The extension could be enough, although I'm thinking if auto-decompression may cause other kind of issues.

Angelmmiguel commented 1 year ago

Hey @k33g!

I plan to start working on this issue and add support for git repositories. I will add support for other protocols / URLs after that 😄

k33g commented 1 year ago

@Angelmmiguel, that's excellent news 🤩

Angelmmiguel commented 1 year ago

@k33g I just merged the changes to run a wws from a remote repository. It's not released yet, but you can already try it in the preview container we build from the main branch 😄.

There are new options for git repositories:

docker run --rm -p 8080:8080 ghcr.io/vmware-labs/wws:preview /wws --help
A WebAssembly framework to develop and run serverless applications anywhere

Usage: wws [OPTIONS] [PATH] [COMMAND]

Commands:
  runtimes  Manage the language runtimes in your project
  help      Print this message or the help of the given subcommand(s)

Arguments:
  [PATH]  Location of the wws project. It could be a local folder or a git repository [default: .]

Options:
      --host <HOSTNAME>          Hostname to initiate the server [default: 127.0.0.1]
  -p, --port <PORT>              Port to initiate the server [default: 8080]
      --prefix <PREFIX>          Prepend the given path to all URLs [default: ]
      --ignore <IGNORE>          Patterns to ignore when looking for worker files [default: ]
  -i, --install-runtimes         Install missing runtimes automatically
      --git-commit <GIT_COMMIT>  Set the commit when using a git repository as project
      --git-tag <GIT_TAG>        Set the tag when using a git repository as project
      --git-branch <GIT_BRANCH>  Set the branch when using a git repository as project
      --git-folder <GIT_FOLDER>  Change the directory when using a git repository as project
  -h, --help                     Print help
  -V, --version                  Print version

And you can now run the examples from this repo directly:

$ docker run --rm -p 8080:8080 ghcr.io/vmware-labs/wws:preview \
  /wws https://github.com/vmware-labs/wasm-workers-server.git \
  --host=0.0.0.0 --git-folder=examples/js-basic --install-runtimes

⚙️  Preparing the project from: https://github.com/vmware-labs/wasm-workers-server.git
⚙️  Loading routes from: /tmp/dd21e3cd6d0f515301e1c7070e562af06074d9e8d10566179f97dba47e74cec9/examples/js-basic
⏳ Loading workers from 1 routes...
✅ Workers loaded in 405.54775ms.
    - http://0.0.0.0:8080/
      => /tmp/dd21e3cd6d0f515301e1c7070e562af06074d9e8d10566179f97dba47e74cec9/examples/js-basic/index.js
🚀 Start serving requests at http://0.0.0.0:8080