Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bots-garden/capsule
Browse files Browse the repository at this point in the history
fighting with go.work.sum
  • Loading branch information
k33g committed Jul 12, 2023
2 parents 20c20bd + 3957d03 commit d201bb6
Show file tree
Hide file tree
Showing 29 changed files with 198 additions and 46 deletions.
9 changes: 5 additions & 4 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ tasks:
#TAG: "v0.3.7" # next release (this is a pre-release)
#TAG: "v0.3.8"
#TAG: "v0.3.9"
TAG: "v0.4.0"
#TAG: "v0.4.0"
TAG: "v0.4.1"

cmds:
- echo "📦 Generating release..."
Expand All @@ -38,13 +39,13 @@ tasks:

remove-tag:
env:
TAG: "v0.4.0"
TAG: "v0.4.1"
cmds:
- git tag -d ${TAG}

build-releases:
env:
TAG: "v0.4.0"
TAG: "v0.4.1"
cmds:
- |
cd capsule-cli
Expand Down Expand Up @@ -77,7 +78,7 @@ tasks:
build-push-docker-image:
vars:
IMAGE_BASE_NAME: "capsule-http"
IMAGE_TAG: "0.4.0"
IMAGE_TAG: "0.4.1"
cmds:
- echo "👋 {{.IMAGE_BASE_NAME}}-{{.GOOS}}-{{.GOARCH}}:{{.IMAGE_TAG}}"
- |
Expand Down
2 changes: 1 addition & 1 deletion capsctl/description.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CapsCtl v0.4.0 🌶️ [chili pepper]
CapsCtl v0.4.1 🫑 [pepper]
2 changes: 1 addition & 1 deletion capsule-cli/description.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[CLI] v0.4.0 🌶️ [chili pepper]
[CLI] v0.4.1 🫑 [pepper]
4 changes: 2 additions & 2 deletions capsule-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module github.com/bots-garden/capsule/capsule-cli

go 1.20

require github.com/tetratelabs/wazero v1.1.0 // indirect
require github.com/tetratelabs/wazero v1.3.0 // indirect

require (
github.com/bots-garden/capsule-host-sdk v0.0.5
github.com/bots-garden/capsule-host-sdk v0.0.6
github.com/gofiber/fiber/v2 v2.44.0
)

Expand Down
20 changes: 15 additions & 5 deletions capsule-http/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ tasks:
GOOS: "linux"
GOARCH: "arm64"
IMAGE_BASE_NAME: "capsule-http"
IMAGE_TAG: "0.4.0"
IMAGE_TAG: "0.4.1"
cmds:
- |
IMAGE_NAME="${IMAGE_BASE_NAME}-${GOOS}-${GOARCH}"
Expand Down Expand Up @@ -332,8 +332,9 @@ tasks:

# task build-capsule-http
# task build-hello-world
# task start-hello-world-for-stress
# task stress-hello-world
stress-hello-world:
start-hello-world-for-stress:
env:
JSON_DATA: '{"name":"Bob Morane","age":42}'
HTTP_PORT: '6666'
Expand All @@ -343,12 +344,21 @@ tasks:
cmds:
- |
echo "🚀 Stressing hello-world..."
./capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT} &
sleep 1
NGROK_AUTHTOKEN=""
./capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT}
stress-hello-world:
env:
JSON_DATA: '{"name":"Bob Morane","age":42}'
HTTP_PORT: '6666'
DOMAIN: 'localhost'
PROTOCOL: 'http'
WASM_FILE: './functions/hello-world/hello-world.wasm'
cmds:
- |
hey -n 300 -c 100 -m POST \
-H "Content-Type: application/json; charset=utf-8" \
-d "${JSON_DATA}" ${PROTOCOL}://${DOMAIN}:${HTTP_PORT} > capsule.http.stress.report.0.4.0.txt
-d "${JSON_DATA}" ${PROTOCOL}://${DOMAIN}:${HTTP_PORT} > capsule.http.stress.report.0.5.0.txt
#- killport ${HTTP_PORT}

build-hey:
Expand Down
46 changes: 46 additions & 0 deletions capsule-http/capsule.http.stress.report.0.5.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

Summary:
Total: 0.0696 secs
Slowest: 0.0432 secs
Fastest: 0.0006 secs
Average: 0.0170 secs
Requests/sec: 4312.2929

Total data: 15900 bytes
Size/request: 53 bytes

Response time histogram:
0.001 [1] |
0.005 [16] |■■■■■■■
0.009 [94] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
0.013 [56] |■■■■■■■■■■■■■■■■■■■■■■■■
0.018 [16] |■■■■■■■
0.022 [16] |■■■■■■■
0.026 [25] |■■■■■■■■■■■
0.030 [33] |■■■■■■■■■■■■■■
0.035 [11] |■■■■■
0.039 [19] |■■■■■■■■
0.043 [13] |■■■■■■


Latency distribution:
10% in 0.0075 secs
25% in 0.0086 secs
50% in 0.0112 secs
75% in 0.0264 secs
90% in 0.0352 secs
95% in 0.0378 secs
99% in 0.0427 secs

Details (average, fastest, slowest):
DNS+dialup: 0.0001 secs, 0.0006 secs, 0.0432 secs
DNS-lookup: 0.0047 secs, 0.0000 secs, 0.0221 secs
req write: 0.0013 secs, 0.0000 secs, 0.0171 secs
resp wait: 0.0081 secs, 0.0002 secs, 0.0225 secs
resp read: 0.0011 secs, 0.0000 secs, 0.0243 secs

Status code distribution:
[200] 300 responses



76 changes: 76 additions & 0 deletions capsule-http/functions/gitlab-webhook/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,78 @@
# Use the GitLab WebHook sample

This sample is a [webhook for a GitLab project](https://docs.gitlab.com/ee/user/project/integrations/webhooks.html) created with Capsule HTTP. For my tests, I use [Ngrok](https://ngrok.com/), so, I can host locally the webhook.

This webhook is listening for the [issue events](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#issue-events) and [notes events](https://docs.gitlab.com/ee/user/project/integrations/webhook_events.html#comment-events) of GitLab, and post an answer when it is triggered.

## Compile the webhook

```bash
tinygo build -o glwebhook.wasm \
-scheduler=none \
--no-debug \
-target wasi ./main.go
```

## Start the webhook

To start this webhook, you need:

- The latest version of Capsule HTTP
- A Ngrok account (with a [AuthToken](https://dashboard.ngrok.com/get-started/your-authtoken))
- A GitLab account (with a [personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html))
- A GitLab project (the GitLab account need to be a member of this project)

If you use a **Ngrok domain** (with a paid account: it means that you can provide a fixed url), start the webhook like this:

```bash
WEBHOOK_TOKEN="ilovepanda" \
GITLAB_API_URL="https://gitlab.com/api/v4" \
GITLAB_BOT_TOKEN="your-personal-access-token" \
GITLAB_BOT_NAME="the-gitlab-handle-of-the-user" \
NGROK_DOMAIN="your-ngrok-domain for example: capsule.ngrok.dev" \
NGROK_AUTHTOKEN="your-ngrok-auth-token" \
./capsule-http \
--wasm=./glwebhook.wasm --httpPort=8090
```

If you use the free plan of **Ngrok** (but you will need to change the url of the webhook at every tests), start the webhook like this (without the `NGROK_DOMAIN`):

```bash
WEBHOOK_TOKEN="ilovepanda" \
GITLAB_API_URL="https://gitlab.com/api/v4" \
GITLAB_BOT_TOKEN="your-personal-access-token" \
GITLAB_BOT_NAME="the-gitlab-handle-of-the-user" \
NGROK_AUTHTOKEN="your-ngrok-auth-token" \
./capsule-http \
--wasm=./glwebhook.wasm --httpPort=8090
```

> **Remarks**:
> - For the both cases, Capsule HTTP will generate a file (`ngrok.url`), so you can easyly retrieve the URL of the ngrok endpoint.
> - You need `WEBHOOK_TOKEN` only if you provided a **Secret token** when you created the webhook, then you will be able to check the token from the header of the query.
## Create the webhook

In your GitLab project, go to **Settings/Webhooks** and create a webhook with the relevant data:

![alt settings](webhook-settings.png "Webhook Settings")

## Use the webhook

### Create an issue

Got to your project and create an issue and notify your bot with its handle into the body of the issue:

![alt create](create-issue.png "Create Issue")

Then you can read the answer from the bot:

![alt answer](issue-bot-answer.png "Bot Answer")

### Add a comment to the issue

Add a comment to the issue and notify your bot with its handle into the body of the comment:

![alt answer](comment-bot-answer.png "Bot Answer")

> **Don't be surprised**: The delay of the comment answer is longer than the one of the issue creation
7 changes: 6 additions & 1 deletion capsule-http/functions/gitlab-webhook/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ description: >
```bash
task build-wasm build-capsule-http start
task build-wasm build-capsule-http start-ngrok-domain
```
GitLab project: https://gitlab.com/bots-garden/capsule-hook
env:
HTTP_PORT: '8090'
DOMAIN: 'localhost'
Expand Down Expand Up @@ -44,6 +45,10 @@ tasks:
start-ngrok:
cmds:
- |
WEBHOOK_TOKEN="ilovepanda" \
GITLAB_API_URL="https://gitlab.com/api/v4" \
GITLAB_BOT_TOKEN="${GITLAB_BOT_TOKEN}" \
GITLAB_BOT_NAME="${GITLAB_BOT_NAME}" \
NGROK_AUTHTOKEN="${NGROK_AUTHTOKEN=}" \
./capsule-http \
--wasm=${WASM_FILE} --httpPort=${HTTP_PORT}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions capsule-http/functions/hello-people/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ tasks:
cmds:
- |
echo "🚀 Testing hello-people..."
NGROK_AUTHTOKEN=""
./capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT}
call:
Expand Down
2 changes: 1 addition & 1 deletion capsule-http/functions/hello-world/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM botsgarden/capsule-http-linux-arm64:0.4.0
FROM botsgarden/capsule-http-linux-arm64:0.4.1
COPY hello-world.wasm .
EXPOSE 8080
CMD ["/capsule-http", "--wasm=./hello-world.wasm", "--httpPort=8080"]
Expand Down
1 change: 1 addition & 0 deletions capsule-http/functions/hello-world/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tasks:
cmds:
- |
echo "🚀 Testing hello-world..."
NGROK_AUTHTOKEN=""
./capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT}
call:
Expand Down
1 change: 1 addition & 0 deletions capsule-http/functions/hello/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tasks:
cmds:
- |
echo "🚀 Testing hello..."
NGROK_AUTHTOKEN=""
./capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT}
call:
Expand Down
1 change: 1 addition & 0 deletions capsule-http/functions/tests/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ tasks:
cmds:
- |
echo "🚀 Testing hello..."
NGROK_AUTHTOKEN=""
./capsule-http --wasm=${WASM_FILE} --httpPort=${HTTP_PORT}
run-go-tests:
Expand Down
4 changes: 2 additions & 2 deletions capsule-http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ require (
)

require (
github.com/bots-garden/capsule-host-sdk v0.0.5
github.com/bots-garden/capsule-host-sdk v0.0.6
github.com/gofiber/fiber/v2 v2.45.0
github.com/tetratelabs/wazero v1.2.0
github.com/tetratelabs/wazero v1.3.0
golang.ngrok.com/ngrok v1.0.0
)

Expand Down
2 changes: 1 addition & 1 deletion capsule-http/tools/description.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[HTTP] v0.4.0 🌶️ [chili pepper]
[HTTP] v0.4.1 🫑 [pepper]
6 changes: 3 additions & 3 deletions docs/capsule-http-faas-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A Capsule HTTP server can start/spawn other Capsule HTTP server processes.
### Install the last version of Capsule HTTP

```bash
VERSION="v0.4.0" OS="linux" ARCH="arm64"
VERSION="v0.4.1" OS="linux" ARCH="arm64"
wget -O capsule-http https://github.com/bots-garden/capsule/releases/download/${VERSION}/capsule-http-${VERSION}-${OS}-${ARCH}
chmod +x capsule-http
sudo cp capsule-http /usr/local/bin/capsule-http
Expand All @@ -24,7 +24,7 @@ capsule-http --version
**CapsCtl** is a CLI to send commands to the Capsule HTTP server when it is unning in **FaaS** mode.

```bash
VERSION="v0.4.0" OS="linux" ARCH="arm64"
VERSION="v0.4.1" OS="linux" ARCH="arm64"
wget -O capsctl https://github.com/bots-garden/capsule/releases/download/${VERSION}/capsctl-${VERSION}-${OS}-${ARCH}
chmod +x capsctl
sudo cp capsctl /usr/local/bin/capsctl
Expand All @@ -51,7 +51,7 @@ You should get an output like this:
```
2023/05/29 15:12:18 🚀 faas mode activated!
2023/05/29 15:12:18 📦 wasm module loaded: ./functions/index-page/index-page.wasm
2023/05/29 15:12:18 💊 Capsule [HTTP] v0.4.0 🌶️ [chili pepper]
2023/05/29 15:12:18 💊 Capsule [HTTP] v0.4.1 🫑 [pepper]
http server is listening on: 8080 🌍
```

Expand Down
6 changes: 3 additions & 3 deletions docs/capsule-http-install-pi.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ssh k33g@capsulezero.local

## Install Capsule HTTP
VERSION="v0.3.4" OS="linux" ARCH="arm64"
VERSION="v0.4.1" OS="linux" ARCH="arm64"
wget -O capsule-http https://github.com/bots-garden/capsule/releases/download/${VERSION}/capsule-http-${VERSION}-${OS}-${ARCH}
chmod +x capsule-http
./capsule-http --version
Expand All @@ -18,7 +18,7 @@ chmod +x capsule-http
Or you can copy the appropriate Capsule HTTP binary from your computer to the RPI:

```bash
scp capsule-http-v0.3.4-linux-arm64 k33g@capsulezero.local:./
scp capsule-http-v0.4.1-linux-arm64 k33g@capsulezero.local:./
```

## Start Capsule HTTP FaaS mode
Expand All @@ -27,7 +27,7 @@ scp capsule-http-v0.3.4-linux-arm64 k33g@capsulezero.local:./
ssh k33g@capsulezero.local -f "./capsule-http --httpPort=8080 --faas=true"
```

Try: `curl http://capsulezero.local:8080`, you should get `Capsule [HTTP] v0.3.9 🥒 [cucumber][faas]`
Try: `curl http://capsulezero.local:8080`, you should get `Capsule [HTTP] v0.4.1 🫑 [pepper][faas]`


## Deploy some functions
Expand Down
8 changes: 4 additions & 4 deletions docs/capsule-http-ovh-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ssh -i ./keys/capsule ubuntu@${OVH_IP}
## Install the last version of Capsule HTTP on the OVH Cloud instance

```bash
VERSION="v0.4.0" OS="linux" ARCH="amd64"
VERSION="v0.4.1" OS="linux" ARCH="amd64"
wget -O capsule-http https://github.com/bots-garden/capsule/releases/download/${VERSION}/capsule-http-${VERSION}-${OS}-${ARCH}

chmod +x capsule-http
Expand Down Expand Up @@ -57,15 +57,15 @@ sudo apt-get install iptables-persistent
If you open this URL https://faas.capsule.foundation/ on your browser, you should see the following message:

```bash
Capsule [HTTP] v0.4.0 🌶️ [chili pepper][faas]
Capsule [HTTP] v0.4.1 🫑 [pepper][faas]
```

### Install the last version of CapsCtl

**CapsCtl** is a CLI to send commands to the Capsule HTTP server when it is running in **FaaS** mode.

```bash
VERSION="v0.4.0" OS="linux" ARCH="arm64"
VERSION="v0.4.1" OS="linux" ARCH="arm64"
wget -O capsctl https://github.com/bots-garden/capsule/releases/download/${VERSION}/capsctl-${VERSION}-${OS}-${ARCH}
chmod +x capsctl
sudo cp capsctl /usr/local/bin/capsctl
Expand Down Expand Up @@ -99,7 +99,7 @@ Create a file named `index.html` in a directory:
<section class="container">
<div>
<h1 class="title">👋 Hello World 🌍</h1>
<h2 class="subtitle">Served with 💜 by Capsule 💊 [HTTP] v0.4.0 🌶️ [chili pepper] </h2>
<h2 class="subtitle">Served with 💜 by Capsule 💊 [HTTP] v0.4.1 🫑 [pepper] </h2>
<h2 class="subtitle">🎉 Hosted on OVH Cloud [🚀 Faas mode]</h2>
<h2 class="subtitle">🥰 With the help of @titimoby</h2>
</div>
Expand Down
Loading

0 comments on commit d201bb6

Please sign in to comment.