From 8b49b0c55a6fe63adc3a23b8979b3a1f02f6bc05 Mon Sep 17 00:00:00 2001 From: jiaxiao zhou Date: Tue, 11 Jul 2023 21:38:55 +0000 Subject: [PATCH] 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 --- Makefile | 8 +++++++- test/k8s/deploy.yaml | 3 +++ test/py-flask/Dockerfile | 18 ++++++++++++++++++ test/py-flask/app.py | 9 +++++++++ test/py-flask/requirements.txt | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/py-flask/Dockerfile create mode 100644 test/py-flask/app.py create mode 100644 test/py-flask/requirements.txt diff --git a/Makefile b/Makefile index 9041b3e7d..4de964c30 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/test/k8s/deploy.yaml b/test/k8s/deploy.yaml index 91f59edbf..2f6bb9bc0 100644 --- a/test/k8s/deploy.yaml +++ b/test/k8s/deploy.yaml @@ -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 \ No newline at end of file diff --git a/test/py-flask/Dockerfile b/test/py-flask/Dockerfile new file mode 100644 index 000000000..c04dd0123 --- /dev/null +++ b/test/py-flask/Dockerfile @@ -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 diff --git a/test/py-flask/app.py b/test/py-flask/app.py new file mode 100644 index 000000000..4a8d043b6 --- /dev/null +++ b/test/py-flask/app.py @@ -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) \ No newline at end of file diff --git a/test/py-flask/requirements.txt b/test/py-flask/requirements.txt new file mode 100644 index 000000000..8ab6294c6 --- /dev/null +++ b/test/py-flask/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file