iT邦幫忙

2023 iThome 鐵人賽

DAY 8
0

Wasm+Runwasi

runwasi

這個專案最初設計出來的目的就是承擔「執行 WASM/WASI 工作負荷」,如同 runc 代表著 run container 的意思,所以它的名字叫做 runwasi

目前 runwasi 已經是被貢獻到 containerd 裡面,因此我們可以直接透過 containerd 來使用 runwasi,像是:ctr ... --runtime=io.containerd.[ wasmedge | wasmtime | wasmer ].v1。除此之外,runwasi 也能作為 CRI Plugin 直接被 Kebelet 所使用。

若讀者想在 k8s 這類的環境裡使用 runwasi,可以透過 kwasm 非常便利且快速地部署在你的環境中。

Runwasi 專案解讀

資料夾結構

runwasi
├── Cargo.lock # Rust 相依性相關檔案
├── Cargo.toml # Rust 設定檔案
├── Dockerfile # 用來編譯與開發 runwasi 的 Dockerfile 
├── LICENSE # 授權
├── MAINTAINERS # 目前的維護者
├── Makefile # 用來編譯 runwasi 的進入檔案
├── NOTICE # Ownership / Copyright 等宣告
├── README.md # 你看到的主文件
├── RELEASE.md # 如何 release 一個 runwasi 的新版本
├── SECURITY.md # 資安相關檔案
├── art # 放 logo 的資料夾
│   └── logo
├── benches # 開發與執行 benchmarks 的資料夾
│   ├── containerd-shim-benchmarks
│   │   ├── Cargo.toml
│   │   └── benches
│   │       └── webassembly-benchmarks.rs
│   └── webassembly-benchmarks
├── crates # 所有 runwasi 包含的工具都在這裡面,包含各個 Wasm Runtime 的實作
│   ├── containerd-shim-wasm # 所有的 Wasm Runtime 都需要依賴在這個框架上,作為一個 Wasm Runtime 實體(instance)
│   │   ├── Cargo.toml
│   │   ├── README.md
│   │   ├── build.rs # 編譯時的進入點
│   │   ├── doc
│   │   │   ├── doc.md
│   │   │   └── header.md
│   │   ├── protos # 定義 sandbox 的 protobuf 檔案
│   │   │   └── sandbox.proto
│   │   └── src
│   │       ├── container
│   │       │   ├── context.rs
│   │       │   ├── engine.rs
│   │       │   ├── mod.rs
│   │       │   └── path.rs
│   │       ├── lib.rs
│   │       ├── sandbox
│   │       │   ├── cli.rs
│   │       │   ├── error.rs
│   │       │   ├── instance.rs
│   │       │   ├── instance_utils.rs
│   │       │   ├── manager.rs
│   │       │   ├── mod.rs
│   │       │   ├── oci.rs
│   │       │   ├── shim.rs
│   │       │   └── stdio.rs
│   │       ├── services
│   │       │   ├── sandbox.rs
│   │       │   └── sandbox_ttrpc.rs
│   │       ├── services.rs
│   │       └── sys
│   │           ├── unix # 跟 UNIX 系統相關的檔案
│   │           │   ├── container
│   │           │   │   ├── executor.rs
│   │           │   │   ├── instance.rs
│   │           │   │   └── mod.rs
│   │           │   ├── metrics.rs
│   │           │   ├── mod.rs
│   │           │   ├── networking.rs
│   │           │   ├── signals.rs
│   │           │   └── stdio.rs
│   │           └── windows # 跟 Windows 系統相關的檔案
│   │               ├── container
│   │               │   ├── instance.rs
│   │               │   └── mod.rs
│   │               ├── metrics.rs
│   │               ├── mod.rs
│   │               ├── networking.rs
│   │               ├── signals.rs
│   │               └── stdio.rs
│   ├── containerd-shim-wasm-test # 測試 containerd-shim-wasm 的資料夾
│   │   ├── ...
│   ├── containerd-shim-wasmedge # WasmEdge runtime 的實作
│   │   ├── Cargo.toml
│   │   └── src
│   │       ├── instance.rs
│   │       ├── lib.rs
│   │       ├── main.rs
│   │       └── tests.rs
│   ├── containerd-shim-wasmer # wasmer runtime 的實作
│   │   ├── Cargo.toml
│   │   └── src
│   │       ├── instance.rs
│   │       ├── lib.rs
│   │       ├── main.rs
│   │       └── tests.rs
│   ├── containerd-shim-wasmtime # wasmtime runtime 的實作
│   │   ├── Cargo.toml
│   │   └── src
│   │       ├── instance.rs
│   │       ├── lib.rs
│   │       ├── main.rs
│   │       └── tests.rs
│   ├── oci-tar-builder # 用來產生 WASM OCI tarball 的工具
│   │   ├── ...
│   └── wasi-demo-app # 示範用的 Wasm 應用程式
│       ├── ...
├── docker-bake.hcl # 用來建立跨平台、跨系統的設定檔案
├── docs
│   └── windows-getting-started.md # 關於在 windows 上的開發說明
├── rust-toolchain.toml # rust toolchain 的設定檔案
├── rustfmt.toml # rust formatter
├── scripts # 協助開發/測試/發布的腳本
│   ├── bins.sh
│   ├── crates.jq
│   ├── dockerfile-utils.sh
│   ├── setup-linux.sh
│   ├── setup-windows.sh
│   ├── test-runner.sh
│   ├── validate-docs.sh
│   └── version.sh
└── test # 測試相關的資料夾
    └── ...

若想學習怎麼處理 Wasm 工作負載

請從 containerd-shim-wasm 資料夾讀起,內容為如何設定沙盒(Sandbox)等實作細節。

若想學習 runwasi 如何與 Wasm Runtime 互動

請看 containerd-shim-[wasmedge|wasmer|wasmtime] 資料夾,可以知道不同的 Wasm Runtimes 怎麼被串接到 containerd-shim-wasm 中。


上一篇
Wasm+Docker Run
下一篇
Wasm+containerd-shim-wasm+container
系列文
關於 WebAssembly 也能變成 Container 的這檔事15
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言