Skip to content

Commit 541ea59

Browse files
Merge pull request #53 from thomastaylor312/feat/migrate_examples
2 parents eaa7d26 + 69ec4cc commit 541ea59

File tree

435 files changed

+31674
-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

+31674
-2
lines changed

.github/workflows/component-go.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ jobs:
8484
example:
8585
- http-server
8686
- http-client
87+
- http-password-checker
8788
- invoke
89+
- sqldb-postgres-query
8890
tinygo-version:
8991
- "0.33.0"
9092
- "0.34.0"
@@ -118,3 +120,30 @@ jobs:
118120
working-directory: "./examples/component/${{ matrix.example }}"
119121
run: |
120122
wash build
123+
124+
- name: run tests
125+
working-directory: "./examples/component/${{ matrix.example }}"
126+
run: go test ./...
127+
128+
# Run the wadm file and make sure it deploys
129+
- name: test component load
130+
shell: bash
131+
working-directory: "./examples/component/${{ matrix.example }}"
132+
# TODO: Add a test to the matrix for testing the running component (i.e. with `curl` or `wash call`)
133+
run: |
134+
set -xe
135+
wash up -d --wadm-manifest wadm.yaml;
136+
sleep 1;
137+
TRIES=0
138+
while [[ $(wash get inventory --output=json | jq '.inventories[0].components | length') -eq 0 ]] ; do
139+
if [[ $TRIES -gt 10 ]]; then
140+
echo "❌ failed to find component in inventory output after deploying example manifest";
141+
exit -1;
142+
fi
143+
TRIES=$((TRIES+1));
144+
sleep 1;
145+
done;
146+
echo "✅ successfully started at least one component";
147+
wash app delete wadm.yaml;
148+
wash down --all;
149+
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)