Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #142 from thomastaylor312/ui/actor
Browse files Browse the repository at this point in the history
feat(petclinic): Compiles Petclinic UI as an actor
  • Loading branch information
thomastaylor312 authored Apr 15, 2022
2 parents e5e7b38 + 86a654d commit 5b46ad4
Show file tree
Hide file tree
Showing 55 changed files with 4,057 additions and 294 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/petclinic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ jobs:
with:
working-directory: petclinic/petclinic-interface/rust

ui_build_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install NPM deps
run: npm install
working-directory: petclinic/petclinic-ui
- name: Test NPM build
run: npm run build
working-directory: petclinic/petclinic-ui

actors_build_check:
runs-on: ubuntu-latest
strategy:
Expand All @@ -47,6 +36,7 @@ jobs:
- petclinic/actors/customers
- petclinic/actors/vets
- petclinic/actors/visits
- petclinic/actors/ui
include:
- working-directory: petclinic/actors/clinicapi
artifact-name: clinicapi
Expand All @@ -56,6 +46,8 @@ jobs:
artifact-name: vets
- working-directory: petclinic/actors/visits
artifact-name: visits
- working-directory: petclinic/actors/ui
artifact-name: ui
steps:
- uses: actions/checkout@v2
- uses: wasmcloud/common-actions/install-wash@main
Expand Down Expand Up @@ -85,6 +77,9 @@ jobs:
- name: Set wash subject key (visits)
if: ${{ matrix.working-directory == 'petclinic/actors/visits' }}
run: echo "WASH_SUBJECT_KEY=${{ secrets.WASMCLOUD_PETCLINIC_VISITS }}" > $GITHUB_ENV
- name: Set wash subject key (ui)
if: ${{ matrix.working-directory == 'petclinic/actors/ui' }}
run: echo "WASH_SUBJECT_KEY=${{ secrets.WASMCLOUD_PETCLINIC_UI }}" > $GITHUB_ENV

- name: Build wasmcloud actor
if: startswith(github.ref, 'refs/tags/') # Only run on tag push
Expand All @@ -100,12 +95,12 @@ jobs:

github_release:
if: startswith(github.ref, 'refs/tags/') # Only run on tag push
needs: actors_build_check
needs: actors_build_check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
artifact-name: [clinicapi, customers, vets, visits]
artifact-name: [clinicapi, customers, vets, visits, ui]
steps:
- name: Download signed actor
uses: actions/download-artifact@v2
Expand All @@ -122,7 +117,7 @@ jobs:
draft: false

artifact_release:
needs: actors_build_check
needs: actors_build_check
if: startswith(github.ref, 'refs/tags/') # Only run on tag push
runs-on: ubuntu-latest
strategy:
Expand All @@ -133,6 +128,7 @@ jobs:
- petclinic/actors/customers
- petclinic/actors/vets
- petclinic/actors/visits
- petclinic/actors/ui
include:
- working-directory: petclinic/actors/clinicapi
artifact-name: clinicapi
Expand All @@ -142,6 +138,8 @@ jobs:
artifact-name: vets
- working-directory: petclinic/actors/visits
artifact-name: visits
- working-directory: petclinic/actors/ui
artifact-name: ui
steps:
- uses: actions/checkout@v2
- name: Download signed actor
Expand Down
2 changes: 1 addition & 1 deletion petclinic/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
subdirs = actors/clinicapi actors/customers actors/vets actors/visits
subdirs = actors/clinicapi actors/customers actors/vets actors/visits actors/ui
top_targets = all push start test clean

include ../build/makefiles/common.mk
Expand Down
45 changes: 38 additions & 7 deletions petclinic/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
# wasmCloud Pet Clinic
The wasmCloud Pet Clinic example application is a WebAssembly and wasmCloud-based reimagining of the classic [Spring Boot microservices Pet Clinic](https://github.com/spring-petclinic/spring-petclinic-microservices) example.
The wasmCloud Pet Clinic example application is a WebAssembly and wasmCloud-based reimagining of the
classic [Spring Boot microservices Pet
Clinic](https://github.com/spring-petclinic/spring-petclinic-microservices) example.

## Application Architecture
The wasmCloud Pet Clinic consists of the following four [actors](./actors):
* [Clinic API](./actors/clinicapi/README.md) - The main JSON (aka "REST") API gateway for interacting with the service
* [Customers](./actors/customers/README.md) - Customers/Owners Actor - roughly equivalent to the original Customers/Owners microservice.
* [Vets](./actors/vets/README.md) - Veterinarians actor, roughly equivalent to the original Vets service.
* [Visits](./actors/visits/README.md) - Visits service, roughly equivalent to the original visits service.
The wasmCloud Pet Clinic consists of the following five [actors](./actors):
* [Clinic API](./actors/clinicapi/README.md) - The main JSON (aka "REST") API gateway for
interacting with the service
* [Customers](./actors/customers/README.md) - Customers/Owners Actor - roughly equivalent to the
original Customers/Owners microservice.
* [Vets](./actors/vets/README.md) - Veterinarians actor, roughly equivalent to the original Vets
service.
* [Visits](./actors/visits/README.md) - Visits service, roughly equivalent to the original visits
service.
* [UI](./actors/ui/README.md) - An actor that contains all assets for the petclinic UI. This actor
will serve the assets through the Clinic API

The wasmCloud Pet Clinic application has a simple architecture: simply start all four of the actors, push a link definition between the **Clinic API** actor and an **HTTP Server** capability provider, and then push link definitions between the 3 remaining actors and a relational database. Lastly, ensure that both the HTTP Server and relational database capability providers are started.
The wasmCloud Pet Clinic application has a simple architecture: simply start all five of the actors,
push a link definition between the **Clinic API** actor and an **HTTP Server** capability provider,
and then push link definitions between the Customers, Vets, and Visits actors and a relational
database. Lastly, ensure that both the HTTP Server and relational database capability providers are
started.

## Running the petclinic

If you'd like a quick out of the box example of the petclinic, you can use the included `run.sh`
script to automatically spin up a running wasmcloud host, database, and all the actors. This does
require `docker` to be installed as all the dependencies are run as docker images. To start
everything, run:

```console
$ ./run.sh all
```

To cleanup everything when you are done:

```console
$ ./run.sh wipe
```

Once it is running, you should be able to access the api on `localhost:8080`
2 changes: 1 addition & 1 deletion petclinic/actors/clinicapi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion petclinic/actors/clinicapi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clinicapi"
version = "0.2.3"
version = "0.3.0"
authors = [ "wasmCloud Team" ]
edition = "2021"

Expand Down
33 changes: 31 additions & 2 deletions petclinic/actors/clinicapi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
use petclinic_interface::{
AddPetRequest, Customers, CustomersSender, Date, ListVisitsRequest, Owner, Pet, PetType,
RecordVisitRequest, Vets, VetsSender, Visit, Visits, VisitsSender,
RecordVisitRequest, Ui, UiSender, Vets, VetsSender, Visit, Visits, VisitsSender,
};
use serde::{Deserialize, Serialize};
use wasmbus_rpc::actor::prelude::*;
use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver};
use wasmcloud_interface_httpserver::{
HeaderMap, HttpRequest, HttpResponse, HttpServer, HttpServerReceiver,
};
use wasmcloud_interface_logging::debug;

const VETS_ACTOR: &str = "petclinic/vets";
const CUSTOMERS_ACTOR: &str = "petclinic/customers";
const VISITS_ACTOR: &str = "petclinic/visits";
const UI_ACTOR: &str = "petclinic/ui";

#[derive(Debug, Default, Actor, HealthResponder)]
#[services(Actor, HttpServer)]
Expand Down Expand Up @@ -56,6 +59,32 @@ impl HttpServer for ClinicapiActor {
("POST", ["owners", owner_id, "pets", pet_id, "visits"]) => {
record_visit(ctx, owner_id, pet_id, deser(&req.body)?).await
}
("GET", _) => {
debug!(
"Got unrecognized path {}. Assuming this is an asset request",
req.path
);
let sender = UiSender::to_actor(UI_ACTOR);
let resp = sender.get_asset(ctx, &req.path).await?;
if !resp.found {
debug!("Asset {} was not found", req.path);
return Ok(HttpResponse::not_found());
}
debug!("Got {} bytes for {}", resp.asset.len(), req.path);
let mut header = HeaderMap::new();
if let Some(content_type) = resp.content_type {
debug!(
"Found content type of {}, setting Content-Type header",
content_type
);
header.insert("Content-Type".to_string(), vec![content_type]);
}
Ok(HttpResponse {
status_code: 200,
header,
body: resp.asset,
})
}
(_, _) => Ok(HttpResponse::not_found()),
}
}
Expand Down
2 changes: 1 addition & 1 deletion petclinic/actors/customers/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion petclinic/actors/customers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "customers"
version = "0.2.3"
version = "0.3.0"
authors = [ "" ]
edition = "2021"

Expand Down
2 changes: 2 additions & 0 deletions petclinic/actors/ui/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = "wasm32-unknown-unknown"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
target/

# dependencies
/node_modules
Expand All @@ -10,6 +10,7 @@

# production
/build
dist/

# misc
.DS_Store
Expand Down
Loading

0 comments on commit 5b46ad4

Please sign in to comment.