Skip to content

Latest commit

 

History

History
136 lines (95 loc) · 8.06 KB

install.md

File metadata and controls

136 lines (95 loc) · 8.06 KB

Install WasmEdge

There are several ways to install WasmEdge depending on your use cases. In this document, we will discuss how to install WasmEdge as a CLI tool, a serverless runtime, a SDK for languages like C, golang and Node.js, and a runtime for Docker and k8s tools.

Use it from command line or in serverless runtimes

To use WasmEdge from the command line or from container-based serverless runtimes (e.g. Vercel or Netlify), you need to install the standalone WasmEdge virtual machine binary program on top of the operating system. You can get WasmEdge release package from its GitHub repository. The example below shows how to install WasmEdge on a typical x86-based Linux system. You can choose a package that meets your own operating system and CPU requirements.

$ curl -sSfL https://github.com/WasmEdge/WasmEdge/releases/download/0.8.2-rc.2/WasmEdge-0.8.2-rc.2-manylinux2014_x86_64.tar.gz -o ./WasmEdge.tar.gz
$ tar --strip-components 2 -xzvf WasmEdge.tar.gz WasmEdge-0.8.2-rc.2-Linux/bin

After installation, you will get two binary programs.

  • wasmedgec is the AOT compiler that compiles WebAssembly bytecode programs (wasm programs) into native code (so program) on your deployment machine.
  • wasmedge is the runtime that executes the wasm program or the AOT compiled so program.

However, in many cases, you need a WebAssembly runtime with WasmEdge's extensions for imaging processing and tensorflow inference etc. You can install the tensorflow build of WasmEdge on your Linux system as follows.

$ curl -L https://github.com/second-state/WasmEdge-tensorflow-tools/releases/download/0.8.0/WasmEdge-tensorflow-tools-0.8.0-manylinux2014_x86_64.tar.gz -o ./WasmEdge-tensorflow-tools-0.8.0-manylinux2014_x86_64.tar.gz
$ tar xzvf WasmEdge-tensorflow-tools-0.8.0-manylinux2014_x86_64.tar.gz wasmedge-tensorflow-lite
$ tar xzvf WasmEdge-tensorflow-tools-0.8.0-manylinux2014_x86_64.tar.gz wasmedgec-tensorflow

$ curl -L https://github.com/second-state/WasmEdge-tensorflow-deps/releases/download/0.8.0/WasmEdge-tensorflow-deps-TFLite-0.8.0-manylinux2014_x86_64.tar.gz -o ./WasmEdge-tensorflow-deps-TFLite-0.8.0-manylinux2014_x86_64.tar.gz
$ tar xzvf WasmEdge-tensorflow-deps-TFLite-0.8.0-manylinux2014_x86_64.tar.gz

After installation, you will get two binary programs with the Tensorflow Lite (TFLite) dependency libraries.

  • wasmedgec-tensorflow is the AOT compiler that compiles WebAssembly bytecode programs (wasm programs) into native code (so program) on your deployment machine. It is aware of WamsEdge's Tensorflow extension API.
  • wasmedge-tensorflow-lite is the runtime that executes the wasm program or the AOT compiled so program with the Tensorflow Lite library.

Most public cloud serverless platforms use Linux-based Docker images as an extension mechanism. You can easily embed the WasmEdge CLI tool into those Docker containers to support WebAssembly-based functions.

Use it as a language SDK

To embed WasmEdge in an application, you will need to install the WasmEdge library SDK. It can then be accessed via a C API or golang API. Below is how to do it in a Linux system.

$ wget https://github.com/second-state/WasmEdge-go/releases/download/v0.8.1/install_wasmedge.sh
$ chmod +x ./install_wasmedge.sh
$ sudo ./install_wasmedge.sh /usr/local

If you also need the image processing and Tensorflow extensions, it is a little more complex.

# Install WasmEdge 
$ wget https://github.com/second-state/WasmEdge-go/releases/download/v0.8.1/install_wasmedge.sh
$ chmod +x ./install_wasmedge.sh
$ sudo ./install_wasmedge.sh /usr/local

# Install WasmEdge Tensorflow extension
$ wget https://github.com/second-state/WasmEdge-go/releases/download/v0.8.1/install_wasmedge_tensorflow_deps.sh
$ wget https://github.com/second-state/WasmEdge-go/releases/download/v0.8.1/install_wasmedge_tensorflow.sh
$ chmod +x ./install_wasmedge_tensorflow_deps.sh
$ chmod +x ./install_wasmedge_tensorflow.sh
$ sudo ./install_wasmedge_tensorflow_deps.sh /usr/local
$ sudo ./install_wasmedge_tensorflow.sh /usr/local

# Install WasmEdge Images extension
$ wget https://github.com/second-state/WasmEdge-go/releases/download/v0.8.1/install_wasmedge_image_deps.sh
$ wget https://github.com/second-state/WasmEdge-go/releases/download/v0.8.1/install_wasmedge_image.sh
$ chmod +x ./install_wasmedge_image_deps.sh
$ chmod +x ./install_wasmedge_image.sh
$ sudo ./install_wasmedge_image_deps.sh /usr/local
$ sudo ./install_wasmedge_image.sh /usr/local

Here is a good example on how to embed WasmEdge Tensorflow SDK into a golang application.

Use it from Node.js

WasmEdge can run WebAssembly functions emebedded in Node.js applications. To install the WasmEdge module in your Node.js environment is easy. Just use the npm tool.

$ npm install -g wasmedge-core # Append --unsafe-perm if permission denied

To install WasmEdge with Tensorflow and other extensions.

$ npm install -g wasmedge-extensions # Append --unsafe-perm if permission denied

The Second State Functions is a WasmEdge-based FaaS service build on Node.js.

Use it with Docker, CRI-O, and Kubernetes

You can also use Docker tools, such as the CRI-O, to manage and execute WebAssembly programs as if they are Docker images. To do that, you need to install the runw runtime into CRI-O. The runw already embeds a WasmEdge runtime so you do not need to install WasmEdge separately.

First, make sure that you are on Ubuntu 20.04 with LLVM-10 installed. If you are on a different platform, please refer to the project documentation on how to build runw for your OS.

$ sudo apt install -y llvm-10-dev liblld-10-dev

Also make sure that you have cri-o, crictl, containernetworking-plugins, and buildah or docker installed.

Next, download the runw binary build.

$ wget https://github.com/second-state/runw/releases/download/0.1.0/runw

Now, you can install runw into CRI-O as an alternative runtime for WebAssembly.

# Get the wasm-pause utility
$ sudo crictl pull docker.io/beststeve/wasm-pause

# Install runw into cri-o
$ sudo cp -v runw /usr/lib/cri-o-runc/sbin/runw
$ sudo chmod +x /usr/lib/cri-o-runc/sbin/runw
$ sudo sed -i -e 's@default_runtime = "runc"@default_runtime = "runw"@' /etc/crio/crio.conf
$ sudo sed -i -e 's@pause_image = "k8s.gcr.io/pause:3.2"@pause_image = "docker.io/beststeve/wasm-pause"@' /etc/crio/crio.conf
$ sudo sed -i -e 's@pause_command = "/pause"@pause_command = "pause.wasm"@' /etc/crio/crio.conf
$ sudo tee -a /etc/crio/crio.conf.d/01-crio-runc.conf <<EOF
[crio.runtime.runtimes.runw]
runtime_path = "/usr/lib/cri-o-runc/sbin/runw"
runtime_type = "oci"
runtime_root = "/run/runw"
EOF

Finally, restart cri-o for the new WebAssembly runner to take effect.

sudo systemctl restart crio

This article shows a complete example on how to use CRI-O to manage a WebAssembly program.