Skip to content

Commit

Permalink
Merge pull request #26 from second-state/hydai/add_preopens_and_mount…
Browse files Browse the repository at this point in the history
…s_tests

Enable tests for the preopens dir with rootfs and mounts
  • Loading branch information
hydai committed Nov 24, 2022
2 parents 860f6c6 + d06e2c3 commit ba7ea90
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ jobs:
sudo ctr run --rm --net-host --env DATABASE_URL=mysql://root:[email protected]:3306/mysql --runtime=io.containerd.wasmedge.v1 docker.io/library/db-demo:latest testdb /query.wasm
sudo ctr run --rm --net-host --env DATABASE_URL=mysql://root:[email protected]:3306/mysql --runtime=io.containerd.wasmedge.v1 docker.io/library/db-demo:latest testdb /crud.wasm
- name: Run rootfs mounts demo conatiner
run: |
sudo ctr run --rm --runtime=io.containerd.wasmedge.v1 \
--mount type=bind,src=$PWD/demo/wasmedge-rootfs-mounts-demo,dst=/mnt,options=rbind:ro \
docker.io/library/preopens-demo:latest preopens /preopens.wasm
- name: Run microservice with database demo conatiner
run: |
nohup sudo ctr run --rm --net-host --env DATABASE_URL=mysql://root:[email protected]:3306/mysql --runtime=io.containerd.wasmedge.v1 docker.io/library/microservice-db-demo:latest testmicroservice &
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "demo/wasinn"]
path = demo/wasinn
url = https://github.com/second-state/WasmEdge-WASINN-examples.git
[submodule "demo/wasmedge-rootfs-mounts-demo"]
path = demo/wasmedge-rootfs-mounts-demo
url = https://github.com/second-state/wasmedge-rootfs-mounts-demo.git
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ MICROSERVICE_DB_IMG_NAME ?= microservice-db-demo:latest
WASINN_DIRS = $(shell find demo/wasinn -type d)
WASINN_FILES = $(shell find demo/wasinn -type f -name '*')
WASINN_IMG_NAME ?= wasinn-demo:latest
PREOPENS_DIRS = $(shell find demo/wasmedge-rootfs-mounts-demo -type d)
PREOPENS_FILES = $(shell find demo/wasmedge-rootfs-mounts-demo -type f -name '*')
PREOPENS_IMG_NAME ?= preopens-demo:latest
export CONTAINERD_NAMESPACE ?= default

TARGET ?= debug
Expand Down Expand Up @@ -80,11 +83,17 @@ demo/out/wasinn_img.tar: demo/images/wasinn.Dockerfile \
mkdir -p $(@D)
docker buildx build --platform=wasi/wasm -o type=docker,dest=$@ -t $(WASINN_IMG_NAME) -f ./demo/images/wasinn.Dockerfile ./demo

demo/out/preopens.tar: demo/images/preopens.Dockerfile \
$(PREOPENS_DIRS) $(PREOPENS_FILES)
mkdir -p $(@D)
docker buildx build --platform=wasi/wasm -o type=docker,dest=$@ -t $(PREOPENS_IMG_NAME) -f ./demo/images/preopens.Dockerfile ./demo

load_demo: demo/out/hyper_img.tar \
demo/out/db_img.tar \
demo/out/reqwest_img.tar \
demo/out/microservice_db_img.tar \
demo/out/wasinn_img.tar
demo/out/wasinn_img.tar \
demo/out/preopens.tar
$(foreach var,$^,\
sudo ctr -n $(CONTAINERD_NAMESPACE) image import $(var);\
)
Expand Down
83 changes: 77 additions & 6 deletions demo/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Demo

## Index
- [Hyper Cleint / Server](https://github.com/CaptainVincent/runwasi/tree/main/demo#demo-1-hyper-cleint--server)
- [Reqwest](https://github.com/CaptainVincent/runwasi/tree/main/demo#demo-2-reqwest)
- [Database](https://github.com/CaptainVincent/runwasi/tree/main/demo#case-3-database)
- [Microservice with Database](https://github.com/CaptainVincent/runwasi/tree/main/demo#case-4-microservice-with-database)
- [WASI NN](https://github.com/CaptainVincent/runwasi/tree/main/demo#case-5-wasi-nn-x86-only)
- [Hyper Cleint / Server](https://github.com/second-state/runwasi/tree/main/demo#demo-1-hyper-cleint--server)
- [Reqwest](https://github.com/second-state/runwasi/tree/main/demo#demo-2-reqwest)
- [Database](https://github.com/second-state/runwasi/tree/main/demo#case-3-database)
- [Microservice with Database](https://github.com/second-state/runwasi/tree/main/demo#case-4-microservice-with-database)
- [WASI NN](https://github.com/second-state/runwasi/tree/main/demo#case-5-wasi-nn-x86-only)
- [WasmEdge rootfs/mounts demo](https://github.com/second-state/runwasi/tree/main/demo#case-6-rootfsmounts-demo)

All below demo cases should be run after all shim components already installed that mentioned in [README.md](../README.md#examples).

Expand Down Expand Up @@ -488,4 +489,74 @@ Executed graph inference
3.) [951](11.5748)lemon
4.) [950](10.4899)orange
5.) [953](9.4834)pineapple, ananas
```
```

## [Case 6. Rootfs/mounts demo](https://github.com/second-state/wasmedge-rootfs-mounts-demo)


### Execution

- Run
```terminal
sudo ctr run --rm --mount type=bind,src=$(pwd)/demo/wasmedge-rootfs-mounts-demo,dst=/mnt,options=rbind:ro --runtime=io.containerd.wasmedge.v1 docker.io/library/preopens-demo:latest preopens /preopens.wasm
```

- Output
```terminal
Recursive list files and folder in "/mnt"
/mnt in "/"
/mnt/.git in "/"
/mnt/Makefile in "/"
/mnt/.gitignore in "/"
/mnt/Cargo.toml in "/"
/mnt/LICENSE in "/"
/mnt/Dockerfile in "/"
/mnt/src in "/"
/mnt/src/main.rs in "/"
Recursive list files and folder in "/mnt" ... done
Recursive list files and folder in "/"
/ in "/"
/mnt in "/"
/mnt/.git in "/"
/mnt/Makefile in "/"
/mnt/.gitignore in "/"
/mnt/Cargo.toml in "/"
/mnt/LICENSE in "/"
/mnt/Dockerfile in "/"
/mnt/src in "/"
/mnt/src/main.rs in "/"
/preopens.wasm in "/"
/test-dir in "/"
/test-dir/.cargo-lock in "/"
/test-dir/wasmedge-rootfs-mounts-demo.wasm in "/"
/test-dir/examples in "/"
/test-dir/deps in "/"
/test-dir/deps/wasmedge_rootfs_mounts_demo-3831c5fb466bd13e.wasm in "/"
/test-dir/deps/same_file-f0d6011a39803642.d in "/"
/test-dir/deps/wasmedge_rootfs_mounts_demo-3831c5fb466bd13e.d in "/"
/test-dir/deps/libwalkdir-0faea8d97cebafaf.rmeta in "/"
/test-dir/deps/walkdir-0faea8d97cebafaf.d in "/"
/test-dir/deps/libwalkdir-0faea8d97cebafaf.rlib in "/"
/test-dir/deps/libsame_file-f0d6011a39803642.rmeta in "/"
/test-dir/deps/libsame_file-f0d6011a39803642.rlib in "/"
/test-dir/.fingerprint in "/"
/test-dir/.fingerprint/walkdir-0faea8d97cebafaf in "/"
/test-dir/.fingerprint/walkdir-0faea8d97cebafaf/lib-walkdir.json in "/"
/test-dir/.fingerprint/walkdir-0faea8d97cebafaf/invoked.timestamp in "/"
/test-dir/.fingerprint/walkdir-0faea8d97cebafaf/dep-lib-walkdir in "/"
/test-dir/.fingerprint/walkdir-0faea8d97cebafaf/lib-walkdir in "/"
/test-dir/.fingerprint/wasmedge-rootfs-mounts-demo-3831c5fb466bd13e in "/"
/test-dir/.fingerprint/wasmedge-rootfs-mounts-demo-3831c5fb466bd13e/dep-bin-wasmedge-rootfs-mounts-demo in "/"
/test-dir/.fingerprint/wasmedge-rootfs-mounts-demo-3831c5fb466bd13e/invoked.timestamp in "/"
/test-dir/.fingerprint/wasmedge-rootfs-mounts-demo-3831c5fb466bd13e/bin-wasmedge-rootfs-mounts-demo.json in "/"
/test-dir/.fingerprint/wasmedge-rootfs-mounts-demo-3831c5fb466bd13e/bin-wasmedge-rootfs-mounts-demo in "/"
/test-dir/.fingerprint/same-file-f0d6011a39803642 in "/"
/test-dir/.fingerprint/same-file-f0d6011a39803642/dep-lib-same-file in "/"
/test-dir/.fingerprint/same-file-f0d6011a39803642/lib-same-file in "/"
/test-dir/.fingerprint/same-file-f0d6011a39803642/invoked.timestamp in "/"
/test-dir/.fingerprint/same-file-f0d6011a39803642/lib-same-file.json in "/"
/test-dir/build in "/"
/test-dir/wasmedge-rootfs-mounts-demo.d in "/"
/test-dir/incremental in "/"
Recursive list files and folder in "/" ... done
```
11 changes: 11 additions & 0 deletions demo/images/preopens.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM --platform=${BUILDPLATFORM} rust:1.65 AS build
RUN rustup target add wasm32-wasi
WORKDIR /opt/preopens
COPY wasmedge-rootfs-mounts-demo .

RUN cargo build --target=wasm32-wasi --release

FROM scratch
COPY --from=build /opt/preopens/target/wasm32-wasi/release/wasmedge-rootfs-mounts-demo.wasm /preopens.wasm
COPY --from=build /opt/preopens/target/wasm32-wasi/release/ /test-dir
ENTRYPOINT ["/preopens.wasm"]
1 change: 1 addition & 0 deletions demo/wasmedge-rootfs-mounts-demo

0 comments on commit ba7ea90

Please sign in to comment.