Skip to content

Commit eb70184

Browse files
committed
[chapter 7] finished pre-review
Signed-off-by: danbugs <[email protected]>
1 parent ce7e4d0 commit eb70184

File tree

8 files changed

+110
-1
lines changed

8 files changed

+110
-1
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Use a lightweight Python base image
2+
FROM python:3.9-slim
3+
4+
WORKDIR /app
5+
6+
# Install Flask
7+
RUN pip install flask
8+
9+
# Copy the app
10+
COPY app.py .
11+
12+
# Expose port 8000
13+
EXPOSE 8000
14+
15+
# Run the server
16+
CMD ["python", "app.py"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# `hello-container2wasm`
2+
3+
## How to run?
4+
5+
```shell
6+
docker build -t python-wasm-webserver .
7+
c2w python-wasm-webserver python-wasm-webserver.wasm
8+
c2w-net --invoke -p localhost:8000:8000 ./python-wasm-webserver-2.wasm --net=socket
9+
curl http://127.0.0.1:8000/
10+
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
@app.route('/')
6+
def hello():
7+
return "hello from inside a container running on Wasm"
8+
9+
if __name__ == '__main__':
10+
app.run(host='0.0.0.0', port=8000)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flask

chapter07/hello-wasm-container/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
```shell
66
cargo build --target wasm32-wasip1 --release
7-
docker buildx build --platform wasi/wasm32 -t hello-wasm-docker .
7+
docker buildx build --load --platform wasi/wasm32 -t hello-wasm-docker .
88
docker run --rm --runtime=io.containerd.wasmtime.v1 --platform=wasi/wasm32 hello-wasm-docker
99
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# `hello-wasmcloud-container`
2+
3+
## How to run?
4+
5+
```shell
6+
docker compose up
7+
wasm app deploy ./wadm.yaml
8+
curl http://127.0.0.1:8000/
9+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# This docker-compose file starts the required services for wasmCloud, which is just:
2+
# a NATS server
3+
# a wasmCloud host
4+
# a wadm server
5+
6+
version: "3"
7+
services:
8+
nats:
9+
image: nats:2.10-alpine
10+
ports:
11+
- "4222:4222"
12+
command: ["-js"]
13+
wasmcloud:
14+
depends_on:
15+
- "nats"
16+
image: wasmcloud/wasmcloud:latest
17+
environment:
18+
RUST_LOG: debug,hyper=info,async_nats=info,oci_client=info,cranelift_codegen=warn
19+
WASMCLOUD_LOG_LEVEL: debug
20+
WASMCLOUD_RPC_HOST: nats
21+
WASMCLOUD_CTL_HOST: nats
22+
ports:
23+
- "8000:8000"
24+
wadm:
25+
depends_on:
26+
- "nats"
27+
image: ghcr.io/wasmcloud/wadm:latest
28+
environment:
29+
- WADM_NATS_SERVER=nats
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: core.oam.dev/v1beta1
2+
kind: Application
3+
metadata:
4+
name: hello-wasmcloud-container
5+
annotations:
6+
description: ''
7+
spec:
8+
components:
9+
- name: http-component
10+
type: component
11+
properties:
12+
image: ghcr.io/wasmcloud/components/http-hello-world-rust:0.1.0
13+
traits:
14+
- type: spreadscaler
15+
properties:
16+
instances: 1
17+
18+
- name: httpserver
19+
type: capability
20+
properties:
21+
image: ghcr.io/wasmcloud/http-server:0.25.0
22+
traits:
23+
- type: link
24+
properties:
25+
target:
26+
name: http-component
27+
namespace: wasi
28+
package: http
29+
interfaces: [incoming-handler]
30+
source:
31+
config:
32+
- name: default-http
33+
properties:
34+
address: 0.0.0.0:8000

0 commit comments

Comments
 (0)