Skip to content

Commit

Permalink
feat: add a new shim for Wasm Workers Server (#88)
Browse files Browse the repository at this point in the history
* feat: add the wasm workers server (wws) shim, examples and required scripts

* feat: update GitHub workflows to test and build wws

* feat: start adding wws information to the README.md file

* fix: update imports in main.rs to fix format

* fix: add missing build-wws-X dependency to the build task

* fix: remove non-relevant login and unused variables. Fix service resources

* fix: point to the right wws crate version. Update wws tests

* fix: skip adding compiling flags in cross

* feat: add quickstart guide and a new wws-python example

* fix: update wws Cargo.toml metadata

* feat: use 3000 port in the wws-shim. Add missing make tasks and deps

* feat: redirect stderr to the pod logs to provide visibility

* fix: set the right path for stderr. Remove unnecesary reference

* fix: rollback to use the right type for the wws serve function

* fix: remove the reference for stderr_path
  • Loading branch information
Angelmmiguel authored May 12, 2023
1 parent 98277b5 commit 88aa1c1
Show file tree
Hide file tree
Showing 26 changed files with 4,877 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
workspaces: |
"containerd-shim-slight-v1 -> target"
"containerd-shim-spin-v1 -> target"
"containerd-shim-wws-v1 -> target"
- name: "Install Rust Wasm targets"
run: |
rustup target add wasm32-wasi
Expand All @@ -47,6 +48,7 @@ jobs:
mkdir _dist
cp containerd-shim-slight-v1/target/${{ matrix.config.arch }}-unknown-linux-musl/release/containerd-shim-*-v1 _dist/
cp containerd-shim-spin-v1/target/${{ matrix.config.arch }}-unknown-linux-musl/release/containerd-shim-*-v1 _dist/
cp containerd-shim-wws-v1/target/${{ matrix.config.arch }}-unknown-linux-musl/release/containerd-shim-*-v1 _dist/
cd _dist
tar czf containerd-wasm-shims-v1-${{ env.RUNNER_OS }}-${{ matrix.config.arch }}.tar.gz containerd-shim-*-v1
- name: upload shim artifacts
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
workspaces: |
"containerd-shim-slight-v1 -> target"
"containerd-shim-spin-v1 -> target"
"containerd-shim-wws-v1 -> target"
- name: "Install Rust Wasm targets"
run: |
rustup target add wasm32-wasi
Expand All @@ -38,6 +39,7 @@ jobs:
workspaces: |
"containerd-shim-slight-v1 -> target"
"containerd-shim-spin-v1 -> target"
"containerd-shim-wws-v1 -> target"
- name: "Install Rust Wasm targets"
run: |
rustup target add wasm32-wasi
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
build:
uses: ./.github/workflows/build.yaml
release:
permissions:
permissions:
contents: write
packages: write
packages: write
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
-p \
_dist/runtime.yaml#example-runtimes \
_dist/workload.yaml#example-workloads \
for f in ./_artifacts/*/*.tar.gz; do gh release upload ${{ env.RELEASE_VERSION }} $f; done
# Setup buildx to build multiarch image: https://github.com/docker/build-push-action/blob/master/docs/advanced/multi-platform.md
Expand Down Expand Up @@ -80,6 +80,15 @@ jobs:
ghcr.io/deislabs/containerd-wasm-shims/examples/slight-rust-hello:latest
context: images/slight
platforms: wasi/wasm
- name: build and push Wasm Workers Server (wws) hello world (JS)
uses: docker/build-push-action@v3
with:
push: true
tags: |
ghcr.io/deislabs/containerd-wasm-shims/examples/wws-js-hello:${{ env.RELEASE_VERSION }}
ghcr.io/deislabs/containerd-wasm-shims/examples/wws-js-hello:latest
context: images/slight
platforms: wasi/wasm
- name: untar x86_64 musl artifacts into ./deployments/k3d/.tmp dir
run: |
mkdir -p ./deployments/k3d/.tmp
Expand Down
37 changes: 32 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PREFIX ?= /usr/local
INSTALL ?= install
TEST_IMG_NAME_SPIN ?= wasmtest_spin:latest
TEST_IMG_NAME_SLIGHT ?= wasmtest_slight:latest
TEST_IMG_NAME_WWS ?= wasmtest_wws:latest
ARCH ?= x86_64
TARGET ?= $(ARCH)-unknown-linux-musl
PYTHON ?= python3
Expand All @@ -14,6 +15,7 @@ test: unit-tests integration-tests
unit-tests: build
cross test --release --manifest-path=containerd-shim-slight-v1/Cargo.toml --target $(TARGET)
cross test --release --manifest-path=containerd-shim-spin-v1/Cargo.toml --target $(TARGET)
cross test --release --manifest-path=containerd-shim-wws-v1/Cargo.toml --target $(TARGET)

.PHONY: integration-tests
integration-tests: build
Expand All @@ -22,14 +24,16 @@ integration-tests: build
$(PYTHON) tests/teardown.py

.PHONY: fmt
fmt:
fmt:
cargo fmt --all --manifest-path=containerd-shim-slight-v1/Cargo.toml -- --check
cargo fmt --all --manifest-path=containerd-shim-spin-v1/Cargo.toml -- --check
cargo fmt --all --manifest-path=containerd-shim-wws-v1/Cargo.toml -- --check
cargo clippy --all-targets --all-features --workspace --manifest-path=containerd-shim-slight-v1/Cargo.toml -- -D warnings
cargo clippy --all-targets --all-features --workspace --manifest-path=containerd-shim-spin-v1/Cargo.toml -- -D warnings
cargo clippy --all-targets --all-features --workspace --manifest-path=containerd-shim-wws-v1/Cargo.toml -- -D warnings

.PHONY: build
build: build-spin-cross-$(TARGET) build-slight-cross-$(TARGET)
build: build-spin-cross-$(TARGET) build-slight-cross-$(TARGET) build-wws-cross-$(TARGET)
echo "Build complete"

.PHONY: install-cross
Expand All @@ -45,6 +49,10 @@ build-spin-cross-%: install-cross
build-slight-cross-%: install-cross
cross build --release --target $* --manifest-path=containerd-shim-slight-v1/Cargo.toml -vvv

.PHONY: build-wws-cross-%
build-wws-cross-%: install-cross
cross build --release --target $* --manifest-path=containerd-shim-wws-v1/Cargo.toml -vvv

.PHONY: build-spin
build-spin:
cargo build --release --manifest-path=containerd-shim-spin-v1/Cargo.toml
Expand All @@ -53,8 +61,12 @@ build-spin:
build-slight:
cargo build --release --manifest-path=containerd-shim-slight-v1/Cargo.toml

.PHONY: build-wws
build-slight:
cargo build --release --manifest-path=containerd-shim-wws-v1/Cargo.toml

.PHONY: install
install: build-spin build-slight
install: build-spin build-slight build-wws
sudo $(INSTALL) containerd-shim-*/target/release/containerd-shim-*-v1 $(PREFIX)/bin

.PHONY: update-deps
Expand All @@ -71,9 +83,15 @@ test/out_slight/img.tar: images/slight/Dockerfile
docker buildx build --platform=wasi/wasm --load -t $(TEST_IMG_NAME_SLIGHT) ./images/slight
docker save -o $@ $(TEST_IMG_NAME_SLIGHT)

load: test/out_spin/img.tar test/out_slight/img.tar
test/out_wws/img.tar: images/wws/Dockerfile
mkdir -p $(@D)
docker buildx build --platform=wasi/wasm --load -t $(TEST_IMG_NAME_WWS) ./images/wws
docker save -o $@ $(TEST_IMG_NAME_WWS)

load: test/out_spin/img.tar test/out_slight/img.tar test/out_wws/img.tar
sudo ctr -n $(CONTAINERD_NAMESPACE) image import test/out_spin/img.tar
sudo ctr -n $(CONTAINERD_NAMESPACE) image import test/out_slight/img.tar
sudo ctr -n $(CONTAINERD_NAMESPACE) image import test/out_wws/img.tar

.PHONY: run_spin
run_spin: install load
Expand All @@ -83,10 +101,15 @@ run_spin: install load
run_slight: install load
sudo ctr run --net-host --rm --runtime=io.containerd.slight.v1 docker.io/library/$(TEST_IMG_NAME_SLIGHT) testslight

.PHONY: run_wws
run_wws: install load
sudo ctr run --net-host --rm --runtime=io.containerd.wws.v1 docker.io/library/$(TEST_IMG_NAME_WWS) testwws

.PHONY: clean
clean: clean-slight clean-spin
clean: clean-slight clean-spin clean-wws
test -f $(PREFIX)/bin/containerd-shim-spin-v1 && sudo rm -rf $(PREFIX)/bin/containerd-shim-spin-v1 || true
test -f $(PREFIX)/bin/containerd-shim-slight-v1 && sudo rm -rf $(PREFIX)/bin/containerd-shim-slight-v1 || true
test -f $(PREFIX)/bin/containerd-shim-wws-v1 && sudo rm -rf $(PREFIX)/bin/containerd-shim-wws-v1 || true
test -d ./test && sudo rm -rf ./test || true

.PHONY: clean-spin
Expand All @@ -96,3 +119,7 @@ clean-spin:
.PHONY: clean-slight
clean-slight:
cargo clean --manifest-path containerd-shim-slight-v1/Cargo.toml

.PHONY: clean-wws
clean-slight:
cargo clean --manifest-path containerd-shim-wws-v1/Cargo.toml
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ This project aims to provide containerd shim implementations that can run Wasm /
- [Start k3d and run a sample WASM application](./deployments/k3d/README.md#how-to-run-the-example).
- [Create a Spin application on k3d](./containerd-shim-spin-v1/quickstart.md)
- [Deploy a SpiderLightning application with k3d](./containerd-shim-slight-v1/quickstart.md)
- [Deploy a Wasm Workers Server application with k3d](./containerd-shim-slight-v1/quickstart.md)

## Containerd Wasm Shims
Each of the shims below leverage runwasi to provide the bridge between K8s and containerd.
Each of the shims below leverage runwasi to provide the bridge between K8s and containerd.

### Spin shim
The Spin shim, as the name implies, is powered by the [Fermyon Spin](https://github.com/fermyon/spin) engine. Spin is an open source framework for building and running fast, secure, and composable cloud microservices with WebAssembly.

If you are curious, [here is the Spin shim source code](./containerd-shim-spin-v1).

### Slight (SpiderLightning) shim
The slight shim is powered by the [Deislabs SpiderLightning](https://github.com/deislabs/spiderlightning) engine. Slight is an open source host, much like Spin, for building and running fast, secure, and composable cloud microservices with WebAssembly. In addition, the slight shim comes with an increasing [array of WebAssembly component capabilities, including underlying implementations](https://github.com/deislabs/spiderlightning/blob/main/docs/primer.md#spiderlightning-capabilities), to consume common application level services.
The slight shim is powered by the [Deislabs SpiderLightning](https://github.com/deislabs/spiderlightning) engine. Slight is an open source host, much like Spin, for building and running fast, secure, and composable cloud microservices with WebAssembly. In addition, the slight shim comes with an increasing [array of WebAssembly component capabilities, including underlying implementations](https://github.com/deislabs/spiderlightning/blob/main/docs/primer.md#spiderlightning-capabilities), to consume common application level services.

If you are curious, [here is the Slight shim source code](./containerd-shim-slight-v1).

### Wasm Workers Server (wws) shim
The `wws` shim is powered by the [Wasm Workers Server](https://github.com/vmware-labs/wasm-workers-server) engine. Wasm Workers Server is an open-source project to develop and run serverless applications on top of WebAssembly. It's based on the "workers" concept from the browser, where you have functions that receives a request, processes it, and provides response. It supports multiple languages, so you can develop your workers with Rust, JavaScript, Python, Ruby and more in the future.

If you are curious, [here is the Wasm Workers Server shim source code](./containerd-shim-wws-v1).

### Building the shims
To build the shims in this project, run `make`.

Expand Down
Loading

0 comments on commit 88aa1c1

Please sign in to comment.