Skip to content

Commit

Permalink
Update the docs to include install deps (#133)
Browse files Browse the repository at this point in the history
Updates the docs to be clear about dependecies and streamlines a few files so there is concistency with make file.

Signed-off-by: James Sturtevant <jstur@microsoft.com>
  • Loading branch information
jsturtevant authored Jun 9, 2023
1 parent c0f8673 commit 1a35dda
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 36 deletions.
23 changes: 12 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ jobs:
sudo apt install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
- name: Setup WasmEdge build env
run: |
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.12.1
echo "LD_LIBRARY_PATH=$HOME/.wasmedge/lib" >> $GITHUB_ENV
- name: Run cargo fmt
make bin/wasmedge
echo "LD_LIBRARY_PATH=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
echo "WASMEDGE_INCLUDE_DIR=$PWD/bin/wasmedge/include" >> $GITHUB_ENV
echo "WASMEDGE_LIB_DIR=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
- name: Run checks
run: |
cargo fmt --all -- --check
- name: Run cargo clippy
run: |
cargo clippy --all --all-targets -- -D warnings
make check
build:
strategy:
matrix:
Expand All @@ -52,8 +51,10 @@ jobs:
sudo apt install -y pkg-config libsystemd-dev libdbus-glib-1-dev build-essential libelf-dev libseccomp-dev libclang-dev
- name: Setup WasmEdge build env
run: |
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.12.1
echo "LD_LIBRARY_PATH=$HOME/.wasmedge/lib" >> $GITHUB_ENV
make bin/wasmedge
echo "LD_LIBRARY_PATH=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
echo "WASMEDGE_INCLUDE_DIR=$PWD/bin/wasmedge/include" >> $GITHUB_ENV
echo "WASMEDGE_LIB_DIR=$PWD/bin/wasmedge/lib" >> $GITHUB_ENV
- name: Build
uses: actions-rs/cargo@v1
with:
Expand All @@ -63,7 +64,7 @@ jobs:
run: ./scripts/validate-docs.sh
- name: Run tests
run: |
sudo -E LD_LIBRARY_PATH=/home/runner/.wasmedge/lib /home/runner/.cargo/bin/cargo test --all --verbose
make test
e2e:
needs: [build]
Expand All @@ -79,7 +80,7 @@ jobs:
- name: setup rust-wasm target
run: rustup target add wasm32-wasi
- name: run
run: make test/k8s/deploy
run: make test/k8s
- name: cleanup
if: always()
run: make test/k8s/clean
18 changes: 16 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ KIND_CLUSTER_NAME ?= containerd-wasm
build:
cargo build $(RELEASE_FLAG)

.PHONY: check
check:
cargo fmt --all -- --check
cargo clippy --all --all-targets -- -D warnings

.PHONY: test
test:
cargo test --all --verbose

.PHONY: install
install:
mkdir -p $(PREFIX)/bin
Expand All @@ -27,8 +36,12 @@ install:
$(INSTALL) target/$(TARGET)/containerd-$(runtime)d $(PREFIX)/bin/; \
)

.PHONY: test-image
test-image: target/wasm32-wasi/$(TARGET)/img.tar

.PHONY: target/wasm32-wasi/$(TARGET)/wasi-demo-app.wasm
target/wasm32-wasi/$(TARGET)/wasi-demo-app.wasm:
rustup target add wasm32-wasi
cd crates/wasi-demo-app && cargo build $(RELEASE_FLAG)

.PHONY: target/wasm32-wasi/$(TARGET)/img.tar
Expand All @@ -50,8 +63,8 @@ test/k8s/cluster: target/wasm32-wasi/$(TARGET)/img.tar bin/kind test/k8s/_out/im
bin/kind create cluster --name $(KIND_CLUSTER_NAME) --image="$(shell cat test/k8s/_out/img)" && \
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) $(<)

.PHONY: test/k8s/deploy
test/k8s/deploy: test/k8s/cluster
.PHONY: test/k8s
test/k8s: test/k8s/cluster
kubectl --context=kind-$(KIND_CLUSTER_NAME) apply -f test/k8s/deploy.yaml
kubectl --context=kind-$(KIND_CLUSTER_NAME) wait deployment wasi-demo --for condition=Available=True --timeout=90s

Expand All @@ -61,6 +74,7 @@ test/k8s/clean:

.PHONY: bin/wasmedge
bin/wasmedge:
mkdir -p ${CURDIR}/bin
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.12.1 -p $(PWD)/bin/wasmedge && \
sudo -E sh -c 'echo "$(PWD)/bin/wasmedge/lib" > /etc/ld.so.conf.d/libwasmedge.conf' && sudo ldconfig

Expand Down
91 changes: 68 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,44 @@ The Wasmedge / Wasmtime engine is shared between all sandboxes in the service.
To use this shim, specify `io.containerd.[ wasmedge | wasmtime ]d.v1` as the runtime to use.
You will need to make sure the `containerd-[ wasmedge | wasmtime ]d` daemon has already been started.

#### Test and demo with containerd
### Contributing

**Attention**
#### Building

Instead of enabling docker-desktop official released feature `use containerd for pulling and storing images`, you can build a local image and interact with the container locally.
1. Install Wasm Edge dependencies

- **Install WasmEdge first (If you choose Wasmedge as your wasm runtime)**
```terminal
make bin/wasmedge/clean
make bin/wasmedge
```

- Install WasmEdge
- Make sure the library is in the search path.
2. Install [youki dependencies](https://github.com/containers/youki#dependencies)

```
sudo apt-get install \
pkg-config \
libsystemd-dev \
libdbus-glib-1-dev \
build-essential \
libelf-dev \
libseccomp-dev \
libclang-dev \
libssl-dev
```

```terminal
$ curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --version=0.12.1
$ sudo -E sh -c 'echo "$HOME/.wasmedge/lib" > /etc/ld.so.conf.d/libwasmedge.conf'
$ sudo ldconfig
3. Build

```
make build
make check
```

- **Run unit test**
### Running unit tests

```terminal
$ cargo test -- --nocapture
make test
```

You should see some output like:
```terminal
running 3 tests
Expand All @@ -173,34 +188,62 @@ test instance::wasitest::test_delete_after_create ... ok
test instance::wasitest::test_wasi ... ok
```

- **Build and install shim components**
### Building the test image

This builds a [wasm application](crates/wasi-demo-app/) and packages it in an OCI format:

```
make test-image
```

### Running integration tests with k3s

```
make test/k3s
```

### Running integration tests with kind

```
make test/k8s
```

## Demo

### Installing the shims for use with Containerd

Make sure you have [installed dependencies](#Building) and install the shims:

```terminal
$ make build
$ sudo make install
make build
sudo make install
```

- **Demo**
Build the test image and load it into contianerd:

Now you can use the test image provided in this repo to have test with, use `make load` to load it into containerd.
```
make test-image
make load
```

- Case 1.
#### Demo 1 using wasmedge

Run it with `sudo ctr run --rm --runtime=io.containerd.[ wasmedge | wasmtime ].v1 ghcr.io/containerd/runwasi/wasi-demo-app:latest testwasm /wasi-demo-app.wasm echo 'hello'`. You should see some output repeated like:

```terminal
$ sudo ctr run --rm --runtime=io.containerd.wasmedge.v1 ghcr.io/containerd/runwasi/wasi-demo-app:latest testwasm /wasi-demo-app.wasm echo 'hello'
sudo ctr run --rm --runtime=io.containerd.wasmedge.v1 ghcr.io/containerd/runwasi/wasi-demo-app:latest testwasm /wasi-demo-app.wasm echo 'hello'
hello
exiting
```

- Case 2.
#### Demo 2 using wasmtime

Run it with `sudo ctr run --rm --runtime=io.containerd.[ wasmedge | wasmtime ].v1 docker.io/library/wasmtest:latest testwasm`.
Run it with `sudo ctr run --rm --runtime=io.containerd.[ wasmedge | wasmtime ].v1 ghcr.io/containerd/runwasi/wasi-demo-app:latest testwasm`.
You should see some output repeated like:

```terminal
$ sudo ctr run --rm --runtime=io.containerd.wasmedge.v1 docker.io/library/wasmtest:latest testwasm
sudo ctr run --rm --runtime=io.containerd.wasmtime.v1 ghcr.io/containerd/runwasi/wasi-demo-app:latest testwasm
This is a song that never ends.
Yes, it goes on and on my friends.
Expand All @@ -215,4 +258,6 @@ So they'll continue singing it forever just because...
(...)
```

To kill the process from the case 2. demo, you can run in other session: `sudo ctr task kill -s SIGKILL testwasm`. And the test binary supports full commands, check [crates/wasi-demo-app/src/main.rs](crates/wasi-demo-app/src/main.rs) to play around more.
To kill the process from demo 2, you can run in other session: `sudo ctr task kill -s SIGKILL testwasm`.

The test binary supports commands for different type of functionality, check [crates/wasi-demo-app/src/main.rs](crates/wasi-demo-app/src/main.rs) to try it out.

0 comments on commit 1a35dda

Please sign in to comment.