runfinch / finch

The Finch CLI is an open source client for container development
https://www.runfinch.com
Apache License 2.0
3.5k stars 91 forks source link

Support Wasm (WebAssembly) images #162

Open pose opened 1 year ago

pose commented 1 year ago

(I'm not an expert in containers, so apologies in advance for any inaccuracies in what I'm about to describe)

What is the problem you're trying to solve?. Docker Desktop 4.15 introduced a Docker+Wasm beta and some Docker experts believe that WebAssembly on the server is the future of computing. In my particular case, I just want to try if I can make it work with finch :)

Describe the feature you'd like I would like to run wasm images using finch.

Additional context

I adapted some of the examples from the Docker+Wasm page, but I couldn't make them work on macOS (Intel):

finch run -dp 8080:8080 \
  --name=wasm-example \
  --runtime=io.containerd.wasmedge.v1 \
  --platform=wasi/wasm32 \
  michaelirwin244/wasm-example

That failed with the following error:

WARN[0000] Platform "wasi/wasm32" seems incompatible with the host platform
"linux/amd64". If you see "exec format error", see
https://github.com/containerd/nerdctl/blob/main/docs/multi-platform.md
error="unknown OCI architecture string: \"wasm32\""
docker.io/michaelirwin244/wasm-example:latest:                                    resolved
manifest-sha256:2a58923a21cb3d45bc4a254120356c15869519603563609eacd8a39b54869b00: done
config-sha256:130eeaf026406b606f00f0e9980fb8b05dbce3f7d21e2b790c32696a376e4463:   done
layer-sha256:e049f00c52896d296a6fa26ea9b3de52f2a1fea9fadfa2c4e0026d15f5563eaa:    done
elapsed: 4.3 s                                                                    total:  1.5 Mi (355.6 KiB/s)
WARN[0004] cannot set cgroup manager to "systemd" for runtime "io.containerd.wasmedge.v1"
FATA[0004] failed to start shim: failed to resolve runtime path: runtime
"io.containerd.wasmedge.v1" binary not installed "containerd-shim-wasmedge-v1":
file does not exist: unknown
FATA[0004] exit status 1

So, after a quick search, it seems that I'm missing containerd-shim-wasmedge-v1. So I cloned the project and I tried to compile it on macOS:

git clone git@github.com:deislabs/containerd-wasm-shims.git
make

but I'm stuck here:

cargo test --manifest-path=containerd-shim-slight-v1/Cargo.toml
   Compiling zstd-safe v5.0.2+zstd.1.5.2
   Compiling zstd-sys v2.0.1+zstd.1.5.2
   Compiling ittapi-rs v0.2.0
   Compiling curl-sys v0.4.56+curl-7.83.1
   Compiling wasmtime-jit v0.39.1
   Compiling libnghttp2-sys v0.1.7+1.45.0
   Compiling openssl-sys v0.9.75
   Compiling zstd v0.11.2+zstd.1.5.2
   Compiling wasmtime-cache v0.39.1
   Compiling openssl v0.10.41
   Compiling libmosquitto-sys v0.2.0
   Compiling wasmtime v0.39.1
   Compiling containerd-shim-wasm v0.1.0 (https://github.com/deislabs/runwasi?branch=main#d03fd0d3)
error[E0432]: unresolved imports `nix::sched::setns`, `nix::sched::unshare`, `nix::sched::CloneFlags`
  --> /Users/apose/.cargo/git/checkouts/runwasi-a2606de7b6c2563b/d03fd0d/crates/containerd-shim-wasm/src/sandbox/manager.rs:20:18
   |
20 | use nix::sched::{setns, unshare, CloneFlags};
   |                  ^^^^^  ^^^^^^^  ^^^^^^^^^^ no `CloneFlags` in `sched`
   |                  |      |
   |                  |      no `unshare` in `sched`
   |                  no `setns` in `sched`

error[E0432]: unresolved import `nix::mount`
  --> /Users/apose/.cargo/git/checkouts/runwasi-a2606de7b6c2563b/d03fd0d/crates/containerd-shim-wasm/src/sandbox/shim.rs:28:10
   |
28 | use nix::mount::{mount, MsFlags};
   |          ^^^^^ could not find `mount` in `nix`

error[E0432]: unresolved imports `nix::sched::setns`, `nix::sched::unshare`, `nix::sched::CloneFlags`
  --> /Users/apose/.cargo/git/checkouts/runwasi-a2606de7b6c2563b/d03fd0d/crates/containerd-shim-wasm/src/sandbox/shim.rs:29:18
   |
29 | use nix::sched::{setns, unshare, CloneFlags};
   |                  ^^^^^  ^^^^^^^  ^^^^^^^^^^ no `CloneFlags` in `sched`
   |                  |      |
   |                  |      no `unshare` in `sched`
   |                  no `setns` in `sched`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `containerd-shim-wasm` due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
make: *** [unit-tests] Error 101

Questions

  1. Once I manage to build containerd-wasm-shims, would that be enough to make it work on macOS?
  2. I tried to install platform "wasi/wasm32", but I have been unabled to find how to do it.
  3. Is this the right place where to open this feature request? Should it be open on nerdctl or any other repo instead? (I don't know yet how everything fits together)

Thanks!

vsiravar commented 1 year ago

Adding related ticket for tracking: https://github.com/containerd/nerdctl/issues/1472

utam0k commented 1 year ago

Once I manage to build containerd-wasm-shims, would that be enough to make it work on macOS? Does it

This probably won't work because of the nix crate https://github.com/nix-rust/nix