Skip to content

Commit

Permalink
test: add a python container to wasmtime shim for testing
Browse files Browse the repository at this point in the history
this commit adds a python container in the test directory.
It also adds a few commands in the makefile to build the python
flask app into a container, load into the kind cluster for testing.
Eventually the wasmtime tests will have both python container and
a wasm contaienr running in a pod.

Signed-off-by: jiaxiao zhou <[email protected]>
  • Loading branch information
Mossaka committed Jul 11, 2023
1 parent 558732d commit 8b49b0c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,16 @@ bin/kind: test/k8s/Dockerfile
test/k8s/_out/img: test/k8s/Dockerfile Cargo.toml Cargo.lock $(shell find . -type f -name '*.rs')
mkdir -p $(@D) && $(DOCKER_BUILD) -f test/k8s/Dockerfile --iidfile=$(@) --load .

.PHONY: test/py-flask
test/py-flask:
docker build -t py-flask-app:latest -f $@/Dockerfile $@
mkdir -p $@/out && docker save -o $@/out/img.tar py-flask-app:latest

.PHONY: test/k8s/cluster
test/k8s/cluster: target/wasm32-wasi/$(TARGET)/img.tar bin/kind test/k8s/_out/img bin/kind
test/k8s/cluster: target/wasm32-wasi/$(TARGET)/img.tar bin/kind test/k8s/_out/img bin/kind test/py-flask
bin/kind create cluster --name $(KIND_CLUSTER_NAME) --image="$(shell cat test/k8s/_out/img)" && \
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) $(<)
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) test/py-flask/out/img.tar

.PHONY: test/k8s
test/k8s: test/k8s/cluster
Expand Down
3 changes: 3 additions & 0 deletions test/k8s/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ spec:
containers:
- name: demo
image: ghcr.io/containerd/runwasi/wasi-demo-app:latest
imagePullPolicy: Never
- name: py-demo
image: py-cmd-app:v1
imagePullPolicy: Never
18 changes: 18 additions & 0 deletions test/py-flask/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# syntax=docker/dockerfile:1.4
FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder

WORKDIR /app

COPY requirements.txt /app
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt

COPY . /app

ENTRYPOINT ["python3"]
CMD ["app.py"]

FROM builder as dev-envs

RUN apk update && \
apk add git
9 changes: 9 additions & 0 deletions test/py-flask/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
return "Hello World!"

if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000)
1 change: 1 addition & 0 deletions test/py-flask/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask

0 comments on commit 8b49b0c

Please sign in to comment.