{"id":13508693,"url":"https://github.com/second-state/runw","last_synced_at":"2025-10-10T02:42:42.342Z","repository":{"id":48562439,"uuid":"330331193","full_name":"second-state/runw","owner":"second-state","description":null,"archived":false,"fork":false,"pushed_at":"2021-07-20T10:03:54.000Z","size":104,"stargazers_count":18,"open_issues_count":15,"forks_count":3,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T08:33:14.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/second-state.png","metadata":{"files":{"readme":"README-zh.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-01-17T06:42:25.000Z","updated_at":"2022-06-23T12:33:42.000Z","dependencies_parsed_at":"2022-09-23T19:01:59.844Z","dependency_job_id":null,"html_url":"https://github.com/second-state/runw","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Frunw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Frunw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Frunw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/second-state%2Frunw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/second-state","download_url":"https://codeload.github.com/second-state/runw/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246314011,"owners_count":20757450,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T02:00:57.072Z","updated_at":"2025-10-10T02:42:37.283Z","avatar_url":"https://github.com/second-state.png","language":"C++","funding_links":[],"categories":["C++","others"],"sub_categories":[],"readme":"# 简介\n\n**RUNW** 是一个 OCI 兼容的运行时，用于在容器环境中运行 WASI 启用的 WebAssembly 文件。我们会示范如何使用 CRI-0 工具。\n\n# 开始\n\n## 先决条件\n\n请安装以下容器管理工具。\n\n* [cri-o](https://cri-o.io/)\n* [crictl](https://github.com/kubernetes-sigs/cri-tools)\n* [containernetworking-plugins](https://github.com/containernetworking/plugins)\n* Optional [buildah](https://github.com/containers/buildah) or [docker](https://github.com/docker/cli) for building container image\n\n## 使用 pre-built runw\n\n### 环境\n\n我们预先构建的二进制文件是基于“ubuntu 20.04”的，它有以下依赖项:\n\n* libLLVM-10\n\n你需要使用以下方法安装依赖项:\n\n```bash\nsudo apt install -y \\\n        llvm-10-dev \\\n        liblld-10-dev\n```\n\n### 从发布页面获得预先构建的 runw\n\n```bash\nwget https://github.com/second-state/runw/releases/download/0.1.1/runw\n```\n\n\u003e 如果你没有使用 Ubuntu 20.04，你需要构建自己的 RUNW 二进制文件。按照附录中的说明操作。\n\n## 安装 runw 到 cri-o\n\n```bash\n# 获得 wasm-pause 实用程序\nsudo crictl pull docker.io/beststeve/wasm-pause\n\n# 安装 runw 到 cri-o\nsudo cp -v runw /usr/lib/cri-o-runc/sbin/runw\nsudo chmod +x /usr/lib/cri-o-runc/sbin/runw\nsudo sed -i -e 's@default_runtime = \"runc\"@default_runtime = \"runw\"@' /etc/crio/crio.conf\nsudo sed -i -e 's@pause_image = \"k8s.gcr.io/pause:3.2\"@pause_image = \"docker.io/beststeve/wasm-pause\"@' /etc/crio/crio.conf\nsudo sed -i -e 's@pause_command = \"/pause\"@pause_command = \"pause.wasm\"@' /etc/crio/crio.conf\nsudo tee -a /etc/crio/crio.conf.d/01-crio-runc.conf \u003c\u003cEOF\n[crio.runtime.runtimes.runw]\nruntime_path = \"/usr/lib/cri-o-runc/sbin/runw\"\nruntime_type = \"oci\"\nruntime_root = \"/run/runw\"\nEOF\n```\n\n## 重启 cri-o\n\n```bash\nsudo systemctl restart crio\n```\n\n# 例子\n\n## 简单的 Wasi 应用\n\n在这个示例中，我们将演示如何创建一个简单的 rust 应用程序，以获取程序参数、检索环境变量、生成随机数、将字符串打印到 stdout 并创建文件。\n\n\n要创建docker镜像和应用程序细节，请参考[简单 Wasi 应用](docs/examples/simple_wasi_app.md).\n\n### 下载 wasi-main docker 镜像\n\nWe've create a docker image called `wasi-main` which is a very light docker image with the `wasi_example_main.wasm` file.我们用`wasi_example_main.wasm` 文件创建了一个名为“ wasi-main”的 docker 镜像， 是一个非常轻的 docker 镜像。\n\n```bash\nsudo crictl pull docker.io/hydai/wasm-wasi-example\n```\n\n### 创建容器配置\n\n创建名为 `container_wasi.json` 的文件，有如下内容：\n\n```json\n{\n  \"metadata\": {\n    \"name\": \"podsandbox1-wasm-wasi\"\n  },\n  \"image\": {\n    \"image\": \"hydai/wasm-wasi-example:latest\"\n  },\n  \"args\": [\n    \"wasi_example_main.wasm\", \"50000000\"\n  ],\n  \"working_dir\": \"/\",\n  \"envs\": [],\n  \"labels\": {\n    \"tier\": \"backend\"\n  },\n  \"annotations\": {\n    \"pod\": \"podsandbox1\"\n  },\n  \"log_path\": \"\",\n  \"stdin\": false,\n  \"stdin_once\": false,\n  \"tty\": false,\n  \"linux\": {\n    \"resources\": {\n      \"memory_limit_in_bytes\": 209715200,\n      \"cpu_period\": 10000,\n      \"cpu_quota\": 20000,\n      \"cpu_shares\": 512,\n      \"oom_score_adj\": 30,\n      \"cpuset_cpus\": \"0\",\n      \"cpuset_mems\": \"0\"\n    },\n    \"security_context\": {\n      \"namespace_options\": {\n        \"pid\": 1\n      },\n      \"readonly_rootfs\": false,\n      \"capabilities\": {\n        \"add_capabilities\": [\n          \"sys_admin\"\n        ]\n      }\n    }\n  }\n}\n```\n\n### 创建沙盒配置文件\n创建名为 `sandbox_config.json` 的文件，包含如下内容：\n\n```json\n{\n  \"metadata\": {\n    \"name\": \"podsandbox12\",\n    \"uid\": \"redhat-test-crio\",\n    \"namespace\": \"redhat.test.crio\",\n    \"attempt\": 1\n  },\n  \"hostname\": \"crictl_host\",\n  \"log_directory\": \"\",\n  \"dns_config\": {\n    \"searches\": [\n      \"8.8.8.8\"\n    ]\n  },\n  \"port_mappings\": [],\n  \"resources\": {\n    \"cpu\": {\n      \"limits\": 3,\n      \"requests\": 2\n    },\n    \"memory\": {\n      \"limits\": 50000000,\n      \"requests\": 2000000\n    }\n  },\n  \"labels\": {\n    \"group\": \"test\"\n  },\n  \"annotations\": {\n    \"owner\": \"hmeng\",\n    \"security.alpha.kubernetes.io/seccomp/pod\": \"unconfined\"\n  },\n  \"linux\": {\n    \"cgroup_parent\": \"pod_123-456.slice\",\n    \"security_context\": {\n      \"namespace_options\": {\n        \"network\": 0,\n        \"pid\": 1,\n        \"ipc\": 0\n      },\n      \"selinux_options\": {\n        \"user\": \"system_u\",\n        \"role\": \"system_r\",\n        \"type\": \"svirt_lxc_net_t\",\n        \"level\": \"s0:c4,c5\"\n      }\n    }\n  }\n}\n```\n\n### 创建 cri-o POD\n```bash\n# 创建 POD。输出将和例子显著不同。\nsudo crictl runp sandbox_config.json\n7992e75df00cc1cf4bff8bff660718139e3ad973c7180baceb9c84d074b516a4\n# Set a helper variable for later use.\nPOD_ID=7992e75df00cc1cf4bff8bff660718139e3ad973c7180baceb9c84d074b516a4\n```\n\n### 创建容器\n```bash\n# 创建容器机器。输出将和例子显著不同。\nsudo crictl create $POD_ID container_wasi.json sandbox_config.json\n1d056e4a8a168f0c76af122d42c98510670255b16242e81f8e8bce8bd3a4476f\n```\n\n### 启动容器\n```bash\n# 列出容器，状态应该为`Created` 已创建\nsudo crictl ps -a\n\nCONTAINER           IMAGE                           CREATED              STATE               NAME                     ATTEMPT             POD ID\n1d056e4a8a168       hydai/wasm-wasi-example:latest   About a minute ago   Created             podsandbox1-wasm-wasi   0                   7992e75df00cc\n\n# 启动容器\nsudo crictl start 1d056e4a8a168f0c76af122d42c98510670255b16242e81f8e8bce8bd3a4476f\n1d056e4a8a168f0c76af122d42c98510670255b16242e81f8e8bce8bd3a4476f\n\n# 再次检查容器状态\n# 如果容器未完成其工作，会看到状态为正在运行 Running 。\n# 应为该例子非常小。你可能在这时候看到已退出 Exited 。\nsudo crictl ps -a\nCONTAINER           IMAGE                           CREATED              STATE               NAME                     ATTEMPT             POD ID\n1d056e4a8a168       hydai/wasm-wasi-example:latest   约1分钟前           Running             podsandbox1-wasm-wasi   0                   7992e75df00cc\n\n# When the container is finished. You can see the state becomes Exited.\nsudo crictl ps -a\nCONTAINER           IMAGE                           CREATED              STATE               NAME                     ATTEMPT             POD ID\n1d056e4a8a168       hydai/wasm-wasi-example:latest   约1分钟前          Exited              podsandbox1-wasm-wasi   0                   7992e75df00cc\n\n# 查看容器的记录\nsudo crictl logs 1d056e4a8a168f0c76af122d42c98510670255b16242e81f8e8bce8bd3a4476f\n\nTest 1: 打印随机数\n随机数: 960251471\n\nTest 2: 打印随机字节\nRandom bytes: [50, 222, 62, 128, 120, 26, 64, 42, 210, 137, 176, 90, 60, 24, 183, 56, 150, 35, 209, 211, 141, 146, 2, 61, 215, 167, 194, 1, 15, 44, 156, 27, 179, 23, 241, 138, 71, 32, 173, 159, 180, 21, 198, 197, 247, 80, 35, 75, 245, 31, 6, 246, 23, 54, 9, 192, 3, 103, 72, 186, 39, 182, 248, 80, 146, 70, 244, 28, 166, 197, 17, 42, 109, 245, 83, 35, 106, 130, 233, 143, 90, 78, 155, 29, 230, 34, 58, 49, 234, 230, 145, 119, 83, 44, 111, 57, 164, 82, 120, 183, 194, 201, 133, 106, 3, 73, 164, 155, 224, 218, 73, 31, 54, 28, 124, 2, 38, 253, 114, 222, 217, 202, 59, 138, 155, 71, 178, 113]\n\nTest 3: 调用 echo 函数\n打印自 wasi: 这是来自主函数\n这是来自主函数\n\n测试 4: 打印环境变量\nThe env vars are as follows.\nPATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\nTERM: xterm\nHOSTNAME: crictl_host\nPATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\nThe args are as follows.\n/var/lib/containers/storage/overlay/006e7cf16e82dc7052994232c436991f429109edea14a8437e74f601b5ee1e83/merged/wasi_example_main.wasm\n50000000\n\n测试 5: 创建文件 `/tmp.txt` 内容为 `This is in a file`\n\nTest 6: 从之前的文件读取内容\n文件内容为 “This is in a file(这在一个文件中)”\n\nTest 7: 删除之前的文件\n```\n\n# 附件\n\n## 从源开始创建\n\n### 获得源代码\n\n```bash\n$ git clone git@github.com:second-state/runw.git\n$ cd runw\n$ git checkout 0.1.1\n```\n\n### 准备环境\n\n#### 使用 docker 镜像\n\n我们的 docker 镜像使用 `ubuntu 20.04` 作为基础。\n\n```bash\n$ docker pull secondstate/runw\n```\n\n#### 或者手动设置环境\n\n```bash\n# 工具和库\n$ sudo apt install -y \\\n        software-properties-common \\\n        cmake \\\n        libboost-all-dev \\\n        libsystemd-dev\n\n# 你将会需要安装 llvm\n$ sudo apt install -y \\\n        llvm-10-dev \\\n        liblld-10-dev\n\n# RUNW 支持 clang++ 和 g++ 编译器\n# 可以选择其中之一来创建此项目\n$ sudo apt install -y gcc g++\n$ sudo apt install -y clang\n```\n创建 RUNW\n\n```bash\n# 在拉去我们的 runw docker 镜像\n$ docker run -it --rm \\\n    -v \u003cpath/to/your/runw/source/folder\u003e:/root/runw \\\n    secondstate/runw:latest\n(docker)$ cd /root/runw\n(docker)$ mkdir -p build \u0026\u0026 cd build\n(docker)$ cmake -DCMAKE_BUILD_TYPE=Release .. \u0026\u0026 make -j\n(docker)$ exit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecond-state%2Frunw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecond-state%2Frunw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecond-state%2Frunw/lists"}