Skip to content

Commit 2560a87

Browse files
feat(examples): Migrates remaining go examples from monorepo
This moves the two examples that weren't moved from the monorepo. This also adds tests and adds simple smoke tests for each component. I also modified the examples job to run once per week to ensure things don't go stale with new versions of `wash` Signed-off-by: Taylor Thomas <[email protected]>
1 parent e8b3f29 commit 2560a87

File tree

435 files changed

+31690
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

435 files changed

+31690
-2
lines changed

.github/workflows/component-go.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Go
22

33
on:
4+
# We trigger this workflow once a week on Saturdays to make sure the examples don't get stale
5+
schedule:
6+
- cron: "0 0 * * 6"
47
push:
58
branches: ["main"]
69
paths:
@@ -84,7 +87,9 @@ jobs:
8487
example:
8588
- http-server
8689
- http-client
90+
- http-password-checker
8791
- invoke
92+
- sqldb-postgres-query
8893
tinygo-version:
8994
- "0.33.0"
9095
- "0.34.0"
@@ -118,3 +123,30 @@ jobs:
118123
working-directory: "./examples/component/${{ matrix.example }}"
119124
run: |
120125
wash build
126+
127+
- name: run tests
128+
working-directory: "./examples/component/${{ matrix.example }}"
129+
run: go test .
130+
131+
# Run the wadm file and make sure it deploys
132+
- name: test component load
133+
shell: bash
134+
working-directory: "./examples/component/${{ matrix.example }}"
135+
# TODO: Add a test to the matrix for testing the running component (i.e. with `curl` or `wash call`)
136+
run: |
137+
set -xe
138+
wash up -d --wadm-manifest wadm.yaml;
139+
sleep 1;
140+
TRIES=0
141+
while [[ $(wash get inventory --output=json | jq '.inventories[0].components | length') -eq 0 ]] ; do
142+
if [[ $TRIES -gt 10 ]]; then
143+
echo "❌ failed to find component in inventory output after deploying example manifest";
144+
exit -1;
145+
fi
146+
TRIES=$((TRIES+1));
147+
sleep 1;
148+
done;
149+
echo "✅ successfully started at least one component";
150+
wash app delete wadm.yaml;
151+
wash down --all;
152+
exit 0;

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ go.work.sum
2323

2424
# env file
2525
.env
26+
.envrc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/*
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# TinyGo HTTP Password Checker
2+
3+
This repository contains a WebAssembly Component written in [TinyGo][tinygo], which:
4+
5+
- Implements a [`wasi:http`][wasi-http]-compliant HTTP handler
6+
- Uses the [`httpserver` provider][httpserver-provider] to serve requests
7+
- Can be declaratively provisioned with [`wadm`][wadm]
8+
9+
[wasi-http]: https://github.com/WebAssembly/wasi-http
10+
[httpserver-provider]: https://github.com/wasmCloud/wasmCloud/tree/main/crates/provider-http-server
11+
[wadm]: https://github.com/wasmCloud/wadm
12+
[tinygo]: https://tinygo.org/getting-started/install/
13+
[wash]: https://wasmcloud.com/docs/ecosystem/wash/
14+
15+
# Dependencies
16+
17+
Before starting, ensure that you have the following installed:
18+
19+
- The [TinyGo toolchain][tinygo]
20+
- [`wash`, the WAsmcloud SHell][wash] installed.
21+
22+
# Quickstart
23+
24+
To get started developing this repository quickly, clone the repo and run `wash dev`:
25+
26+
```console
27+
wash dev
28+
```
29+
30+
`wash dev` does many things for you:
31+
32+
- Starts the [wasmCloud host][wasmcloud-host] that can run your WebAssembly component
33+
- Builds this project
34+
- Builds a declarative WADM manifest consisting of:
35+
- Your locally built component
36+
- A [HTTP server provider][httpserver-provider] which will receive requests from the outside world (on port 8000 by default)
37+
- Necessary links between providers and your component so your component can handle web traffic
38+
- Deploys the built manifest (i.e all dependencies to run this application) locally
39+
- Watches your code for changes and re-deploys when necessary.
40+
41+
[wasmcloud-host]: https://wasmcloud.com/docs/concepts/hosts
42+
43+
## Send a request to the running component
44+
45+
Once `wash dev` is serving your component, to send a request to the running component (via the HTTP server provider):
46+
47+
```console
48+
curl localhost:8000/api/v1/check -d '{"value": "tes12345!"}'
49+
```
50+
51+
You should see a JSON response like:
52+
53+
```json
54+
{
55+
"valid": false, "message": "insecure password, try including more special characters, using uppercase letters or using a longer password"
56+
}
57+
```
58+
59+
## Adding Capabilities
60+
61+
To learn how to extend this example with additional capabilities, see the [Adding Capabilities](https://wasmcloud.com/docs/tour/adding-capabilities?lang=rust) section of the wasmCloud documentation.
62+
63+
# Issues/ FAQ
64+
65+
<summary>
66+
<description>
67+
68+
## `curl` produces a "failed to invoke" error
69+
70+
</description>
71+
72+
If `curl`ing produces
73+
74+
```
75+
➜ curl localhost:8000
76+
failed to invoke `wrpc:http/incoming-handler.handle`: failed to invoke `wrpc:http/[email protected]`: failed to shutdown synchronous parameter channel: not connected%
77+
```
78+
79+
You *may* need to just wait a little bit -- the HTTP server takes a second or two to start up.
80+
81+
If the issue *persists*, you *may* have a lingering HTTP server provider running on your system. You can use `pgrep` to find it:
82+
83+
```console
84+
pgrep -la ghcr_io
85+
4007604 /tmp/wasmcloudcache/NBCBQOZPJXTJEZDV2VNY32KGEMTLFVP2XJRZJ5FWEJJOXESJXXR2RO46/ghcr_io_wasmcloud_http_server_0_23_1
86+
```
87+
88+
</summary>

0 commit comments

Comments
 (0)