Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e tests for Wasm OCI artifact #661

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ install/oci/all: test-image/oci/clean install test-image/oci load/oci
test-image: dist/img.tar

.PHONY: test-image/oci
test-image/oci: dist/img-oci.tar
test-image/oci: dist/img-oci.tar dist/img-oci-artifact.tar

.PHONY: test-image/clean
test-image/clean:
Expand All @@ -172,6 +172,7 @@ test-image/clean:
.PHONY: test-image/oci/clean
test-image/oci/clean:
rm -rf target/wasm32-wasi/$(OPT_PROFILE)/img-oci.tar
rm -rf target/wasm32-wasi/$(OPT_PROFILE)/img-oci-artifact.tar

.PHONY: demo-app
demo-app: target/wasm32-wasi/$(OPT_PROFILE)/wasi-demo-app.wasm
Expand All @@ -190,24 +191,34 @@ dist/img.tar:
[ -f $(PWD)/dist/img.tar ] || $(MAKE) target/wasm32-wasi/$(OPT_PROFILE)/img.tar
[ -f $(PWD)/dist/img.tar ] || cp target/wasm32-wasi/$(OPT_PROFILE)/img.tar "$@"

dist/img-oci.tar: target/wasm32-wasi/$(OPT_PROFILE)/img-oci.tar
dist/img-oci.tar: target/wasm32-wasi/$(OPT_PROFILE)/img-oci.tar
@mkdir -p "dist/"
cp "$<" "$@"

dist/img-oci-artifact.tar: target/wasm32-wasi/$(OPT_PROFILE)/img-oci-artifact.tar
@mkdir -p "dist/"
cp "$<" "$@"

load: dist/img.tar
sudo ctr -n $(CONTAINERD_NAMESPACE) image import --all-platforms $<

CTR_VERSION := $(shell sudo ctr version | sed -n -e '/Version/ {s/.*: *//p;q;}')
load/oci: dist/img-oci.tar
load/oci: dist/img-oci.tar dist/img-oci-artifact.tar
@echo $(CTR_VERSION)\\nv1.7.7 | sort -crV || @echo $(CTR_VERSION)\\nv1.6.25 | sort -crV || (echo "containerd version must be 1.7.7+ or 1.6.25+ was $(CTR_VERSION)" && exit 1)
@echo using containerd $(CTR_VERSION)
sudo ctr -n $(CONTAINERD_NAMESPACE) image import --all-platforms $<
sudo ctr -n $(CONTAINERD_NAMESPACE) image import --all-platforms dist/img-oci-artifact.tar

.PHONY:
target/wasm32-wasi/$(OPT_PROFILE)/img-oci.tar: target/wasm32-wasi/$(OPT_PROFILE)/wasi-demo-app.wasm
mkdir -p ${CURDIR}/bin/$(OPT_PROFILE)/
cargo run --bin oci-tar-builder -- --name wasi-demo-oci --repo ghcr.io/containerd/runwasi --tag latest --module ./target/wasm32-wasi/$(OPT_PROFILE)/wasi-demo-app.wasm -o target/wasm32-wasi/$(OPT_PROFILE)/img-oci.tar

.PHONY:
target/wasm32-wasi/$(OPT_PROFILE)/img-oci-artifact.tar: target/wasm32-wasi/$(OPT_PROFILE)/wasi-demo-app.wasm
mkdir -p ${CURDIR}/bin/$(OPT_PROFILE)/
cargo run --bin oci-tar-builder -- --name wasi-demo-oci-artifact --as-artifact --repo ghcr.io/containerd/runwasi --tag latest --module ./target/wasm32-wasi/$(OPT_PROFILE)/wasi-demo-app.wasm -o target/wasm32-wasi/$(OPT_PROFILE)/img-oci-artifact.tar

bin/kind: test/k8s/Dockerfile
$(DOCKER_BUILD) --output=bin/ -f test/k8s/Dockerfile --target=kind .

Expand Down Expand Up @@ -240,8 +251,9 @@ test/k8s/deploy-workload-%: test/k8s/clean test/k8s/cluster-%
kubectl --context=kind-$(KIND_CLUSTER_NAME) wait deployment wasi-demo --for condition=Available=True --timeout=5s

.PHONY: test/k8s/deploy-workload-oci-%
test/k8s/deploy-workload-oci-%: test/k8s/clean test/k8s/cluster-% dist/img-oci.tar
test/k8s/deploy-workload-oci-%: test/k8s/clean test/k8s/cluster-% dist/img-oci.tar dist/img-oci-artifact.tar test/k8s/cluster-%
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) dist/img-oci.tar
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) dist/img-oci-artifact.tar
kubectl --context=kind-$(KIND_CLUSTER_NAME) apply -f test/k8s/deploy.oci.yaml
kubectl --context=kind-$(KIND_CLUSTER_NAME) wait deployment wasi-demo --for condition=Available=True --timeout=90s
# verify that we are still running after some time
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,15 @@ sudo ctr run --rm --runtime=io.containerd.wasmtime.v1 ghcr.io/containerd/runwasi
hello
exiting
```

### Demo 3 using Wasm OCI Artifact

The [CNCF tag-runtime wasm working group](https://tag-runtime.cncf.io/wgs/wasm/charter/) has a [OCI Artifact format for Wasm](https://tag-runtime.cncf.io/wgs/wasm/deliverables/wasm-oci-artifact/). This is a new Artifact type that enable the usage across projects beyond just runwasi, see the https://tag-runtime.cncf.io/wgs/wasm/deliverables/wasm-oci-artifact/#implementations

```
make test-image/oci
make load/oci
make test/k8s-oci-wasmtime
```

> note: We are using a kubernetes cluster to run here since containerd's ctr has a bug that results in ctr: `unknown image config media type application/vnd.wasm.config.v0+json`
5 changes: 4 additions & 1 deletion crates/containerd-shim-wasm/src/container/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub trait Engine: Clone + Send + Sync + 'static {
/// Runtimes can override this to support other layer types
/// such as lays that contain runtime specific configuration
fn supported_layers_types() -> &'static [&'static str] {
&["application/vnd.bytecodealliance.wasm.component.layer.v0+wasm"]
&[
"application/vnd.bytecodealliance.wasm.component.layer.v0+wasm",
"application/wasm",
]
}

/// Precompile passes supported OCI layers to engine for compilation
Expand Down
4 changes: 4 additions & 0 deletions test/k8s/deploy.oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ spec:
- name: demo
image: ghcr.io/containerd/runwasi/wasi-demo-oci:latest
imagePullPolicy: Never
- name: demo-artifact
image: ghcr.io/containerd/runwasi/wasi-demo-oci-artifact:latest
imagePullPolicy: Never
command: ["wasi-demo.wasm"]
- name: nginx
image: docker.io/nginx:latest
ports:
Expand Down
Loading