Skip to content

Commit

Permalink
Merge pull request #11 from redbadger/products-service-spin
Browse files Browse the repository at this point in the history
Deployment of products service to local wasmCloud
  • Loading branch information
StuartHarris authored Aug 15, 2024
2 parents 18d9d35 + 91d7ae3 commit 0295b55
Show file tree
Hide file tree
Showing 78 changed files with 648 additions and 463 deletions.
1 change: 1 addition & 0 deletions platform-wasmcloud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.wasm
36 changes: 36 additions & 0 deletions platform-wasmcloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### Deploy to local wasmCloud

## Setup

### wasmCloud

Install `wash` with `brew install wash`.

```bash
wash --version
# wash 0.30.0
```

run

```bash
wash up -d
```

### Build and sign the components

```bash
./build_and_sign.fish
```

### Deploy the components with `wadm`

```bash
./up.fish
```

### Delete the application with `wadm`

```bash
./down.fish
```
30 changes: 30 additions & 0 deletions platform-wasmcloud/build_and_sign.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env fish

set SCRIPT_DIR (dirname (realpath (status -f)))
set OUTPUT_DIR $SCRIPT_DIR/signed/
set COMPONENT_DIR (realpath $SCRIPT_DIR/../wasm-components/rust)
set INPUT_DIR $COMPONENT_DIR/target/wasm32-wasip2/release/

mkdir -p $OUTPUT_DIR

pushd $COMPONENT_DIR

### cargo
# cargo build --release
# pushd $INPUT_DIR
# for component in data_init inventory_service orders_service products_service http_controller notification_service
# wash claims sign {$component}.wasm
# mv {$component}_s.wasm $OUTPUT_DIR
# end
# popd

### wash
for component in data-init inventory-service orders-service products-service http-controller notification-service
pushd $component
RUSTUP_TOOLCHAIN=stable wash build
set COMPONENT (string replace -a '-' _ $component)
cp build/{$COMPONENT}_s.wasm $OUTPUT_DIR
popd
end

popd
10 changes: 8 additions & 2 deletions platform-wasmcloud/create_configs.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#!/usr/bin/env bash
set -eu

echo setting up configs...
wash config put default-nats subscriptions="platform-poc.order-notification"
wash config put default-redis url="redis://127.0.0.1:6379"
wash config put default-http address="127.0.0.1:8080"
wash config put default-pg POSTGRES_HOST=localhost POSTGRES_PORT=5432 POSTGRES_USERNAME=${POSTGRES_USERNAME} POSTGRES_PASSWORD=${POSTGRES_PASSWORD} POSTGRES_TLS_REQUIRED=false POSTGRES_DATABASE=${POSTGRES_DATABASE}
wash config put default-pg \
POSTGRES_HOST=localhost \
POSTGRES_PORT=5432 \
POSTGRES_USERNAME=${POSTGRES_USERNAME:-postgres} \
POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres} \
POSTGRES_TLS_REQUIRED=false \
POSTGRES_DATABASE=${POSTGRES_DATABASE:-postgres}

echo
echo "printing configs..."
Expand All @@ -13,4 +20,3 @@ echo "default-nats: $(wash config get default-nats)"
echo "default-redis: $(wash config get default-redis)"
echo "default-http: $(wash config get default-http)"
echo "default-pg: $(wash config get default-pg)"

13 changes: 13 additions & 0 deletions platform-wasmcloud/down.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env fish

wash down --all

pushd /tmp
if test -f wash-ui.pid
set PID (cat wash-ui.pid)
rm -f wash-ui.pid wash-ui.out
if test -n "$PID"
kill $PID
end
end
popd
4 changes: 4 additions & 0 deletions platform-wasmcloud/restart.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env fish

./stop.fish
./start.fish
3 changes: 3 additions & 0 deletions platform-wasmcloud/start.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env fish

wash app deploy ./wadm.yaml
3 changes: 3 additions & 0 deletions platform-wasmcloud/stop.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env fish

wash app delete ./wadm.yaml
11 changes: 11 additions & 0 deletions platform-wasmcloud/up.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env fish

wash up -d

pushd /tmp
status job-control full
nohup wash ui > wash-ui.out &
cat wash-ui.out
set PID $last_pid
echo $PID > wash-ui.pid
popd
79 changes: 50 additions & 29 deletions platform-wasmcloud/wadm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@ metadata:
description: "TODO: Add a description for the application"
spec:
components:
#################### COMPONENTS ####################
#################### COMPONENTS ####################
- name: data-init
type: component
properties:
image: file://../wasm-components/rust/data-init/build/data_init_s.wasm
image: file://signed/data_init_s.wasm
id: data-init
traits:
- type: spreadscaler
properties:
replicas: 1
instances: 1
- type: link
properties:
target: sqldb-postgres
namespace: wasmcloud
package: postgres
interfaces: [query]
target_config:
- name: default-pg
- name: online_store_poc-default_pg
- type: link
properties:
target: kvredis
target: kv-redis
namespace: wasi
package: keyvalue
interfaces: [store]
target_config:
- name: default-redis
- name: online_store_poc-default_redis

- name: http-controller
type: component
properties:
image: file://../wasm-components/rust/http-controller/build/http_controller_s.wasm
image: file://signed/http_controller_s.wasm
id: http-controller
traits:
- type: spreadscaler
properties:
replicas: 1
instances: 20
- type: link
properties:
target: products-service
Expand Down Expand Up @@ -71,66 +71,66 @@ spec:
- name: products-service
type: component
properties:
image: file://../wasm-components/rust/products-service/build/products_service_s.wasm
image: file://signed/products_service_s.wasm
id: products-service
traits:
- type: spreadscaler
properties:
replicas: 1
instances: 10
- type: link
properties:
target: kvredis
target: kv-redis
namespace: wasi
package: keyvalue
interfaces: [store]
target_config:
- name: default-redis
- name: online_store_poc-default_redis

- name: inventory-service
type: component
properties:
image: file://../wasm-components/rust/inventory-service/build/inventory_service_s.wasm
image: file://signed/inventory_service_s.wasm
id: inventory-service
traits:
- type: spreadscaler
properties:
replicas: 1
instances: 10
- type: link
properties:
target: sqldb-postgres
namespace: wasmcloud
package: postgres
interfaces: [query]
target_config:
- name: default-pg
- name: online_store_poc-default_pg

- name: notification-service
type: component
properties:
image: file://../wasm-components/rust/notification-service/build/notification_service_s.wasm
image: file://signed/notification_service_s.wasm
id: notification-service
traits:
- type: spreadscaler
properties:
replicas: 1
instances: 10

- name: orders-service
type: component
properties:
image: file://../wasm-components/rust/orders-service/build/orders_service_s.wasm
image: file://signed/orders_service_s.wasm
id: orders-service
traits:
- type: spreadscaler
properties:
replicas: 1
instances: 10
- type: link
properties:
target: sqldb-postgres
namespace: wasmcloud
package: postgres
interfaces: [query]
target_config:
- name: default-pg
- name: online_store_poc-default_pg
- type: link
properties:
target: inventory-service
Expand All @@ -144,39 +144,58 @@ spec:
package: messaging
interfaces: [consumer]

#################### CAPABILITIES ####################
#################### CAPABILITIES ####################

- name: httpserver
- name: http-server
type: capability
properties:
image: ghcr.io/wasmcloud/http-server:0.20.1
image: ghcr.io/wasmcloud/http-server:0.22.0
id: http-server
traits:
- type: link
properties:
name: http-server
target: http-controller
namespace: wasi
package: http
interfaces: [incoming-handler]
source_config:
- name: default-http
properties:
port: "8080"

- name: kvredis
- name: kv-redis
type: capability
properties:
image: ghcr.io/wasmcloud/keyvalue-redis:0.24.0
image: ghcr.io/wasmcloud/keyvalue-redis:0.27.0
id: kv-redis
config:
- name: default-redis
properties:
url: "redis://127.0.0.1:6379"

- name: sqldb-postgres
type: capability
properties:
image: ghcr.io/wasmcloud/sqldb-postgres:0.1.0
id: sql-postgres
image: ghcr.io/wasmcloud/sqldb-postgres:0.2.0
# this one also works ...
# image: ghcr.io/wasmcloud/sqldb-postgres:877830d
# but 0.3.0 is broken. Have pinged Victor Adossi at Cosmonic in slack
id: sqldb-postgres
config:
- name: default-pg
properties:
POSTGRES_HOST: localhost
POSTGRES_PORT: "5432"
POSTGRES_USERNAME: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_TLS_REQUIRED: "false"
POSTGRES_DATABASE: postgres

- name: nats
type: capability
properties:
image: ghcr.io/wasmcloud/messaging-nats:0.20.0
image: ghcr.io/wasmcloud/messaging-nats:0.22.0
id: nats
traits:
- type: link
Expand All @@ -186,4 +205,6 @@ spec:
package: messaging
interfaces: [handler]
source_config:
- name: default-nats
- name: default-nats
properties:
subscriptions: "platform-poc.order-notification"
File renamed without changes.
29 changes: 29 additions & 0 deletions wasm-components/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Wasm Components

The Wasm Components and their various configurations for deployment.

They are currently written in Rust, but could be written in any language that compiles to Wasm.

## Components

### [Data init](rust/data-init)
- sets up the various data stores

### [HTTP controller](rust/http-controller)
- routes HTTP requests to the appropriate service

### [Products Service](rust/products-service)
- manages the products in **key-value store**

### [Inventory Service](rust/inventory-service)
- manages the inventory of products in **postgres**

### [Orders Service](rust/orders-service)
- manages the orders in **postgres**
- calls `inventory-service`
- does not call `products-service`, although it probs should
- publishes `OrderNotification` events to **NATS**

### [Notification Service](rust/notification-service)
- subscribes to `OrderNotification` events from **NATS**
- prints received messages to `stdout`
1 change: 1 addition & 0 deletions wasm-components/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading

0 comments on commit 0295b55

Please sign in to comment.