Skip to content

Commit 8b49b0c

Browse files
committed
test: add a python container to wasmtime shim for testing
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]>
1 parent 558732d commit 8b49b0c

File tree

5 files changed

+38
-1
lines changed

5 files changed

+38
-1
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ bin/kind: test/k8s/Dockerfile
6767
test/k8s/_out/img: test/k8s/Dockerfile Cargo.toml Cargo.lock $(shell find . -type f -name '*.rs')
6868
mkdir -p $(@D) && $(DOCKER_BUILD) -f test/k8s/Dockerfile --iidfile=$(@) --load .
6969

70+
.PHONY: test/py-flask
71+
test/py-flask:
72+
docker build -t py-flask-app:latest -f $@/Dockerfile $@
73+
mkdir -p $@/out && docker save -o $@/out/img.tar py-flask-app:latest
74+
7075
.PHONY: test/k8s/cluster
71-
test/k8s/cluster: target/wasm32-wasi/$(TARGET)/img.tar bin/kind test/k8s/_out/img bin/kind
76+
test/k8s/cluster: target/wasm32-wasi/$(TARGET)/img.tar bin/kind test/k8s/_out/img bin/kind test/py-flask
7277
bin/kind create cluster --name $(KIND_CLUSTER_NAME) --image="$(shell cat test/k8s/_out/img)" && \
7378
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) $(<)
79+
bin/kind load image-archive --name $(KIND_CLUSTER_NAME) test/py-flask/out/img.tar
7480

7581
.PHONY: test/k8s
7682
test/k8s: test/k8s/cluster

test/k8s/deploy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ spec:
2424
containers:
2525
- name: demo
2626
image: ghcr.io/containerd/runwasi/wasi-demo-app:latest
27+
imagePullPolicy: Never
28+
- name: py-demo
29+
image: py-cmd-app:v1
2730
imagePullPolicy: Never

test/py-flask/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# syntax=docker/dockerfile:1.4
2+
FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder
3+
4+
WORKDIR /app
5+
6+
COPY requirements.txt /app
7+
RUN --mount=type=cache,target=/root/.cache/pip \
8+
pip3 install -r requirements.txt
9+
10+
COPY . /app
11+
12+
ENTRYPOINT ["python3"]
13+
CMD ["app.py"]
14+
15+
FROM builder as dev-envs
16+
17+
RUN apk update && \
18+
apk add git

test/py-flask/app.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from flask import Flask
2+
app = Flask(__name__)
3+
4+
@app.route('/')
5+
def hello():
6+
return "Hello World!"
7+
8+
if __name__ == '__main__':
9+
app.run(host='0.0.0.0', port=8000)

test/py-flask/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

0 commit comments

Comments
 (0)