-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
313 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
capsule | ||
cc | ||
capsule-registry | ||
registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Capsule Wasm Registry | ||
|
||
> 🚧 wip | ||
## Start the registry | ||
|
||
```bash | ||
DOWNLOADED_FILES_PATH="${PWD}/registry/functions" | ||
echo "${DOWNLOADED_FILES_PATH}" | ||
|
||
./capsule-registry \ | ||
-files="${DOWNLOADED_FILES_PATH}" \ | ||
-httpPort=4999 | ||
``` | ||
|
||
## Publish wasm modules to the registry | ||
|
||
```bash | ||
curl -X POST http://localhost:4999/upload/k33g/hello/0.0.0 \ | ||
-F "file=@./capsule-hello/hello.wasm" \ | ||
-F "info=hello function from @k33g" \ | ||
-H "Content-Type: multipart/form-data" | ||
|
||
curl -X POST http://localhost:4999/upload/k33g/hey/0.0.0 \ | ||
-F "file=@./capsule-hey/hey.wasm" \ | ||
-F "info=hello hey from @k33g" \ | ||
-H "Content-Type: multipart/form-data" | ||
``` | ||
|
||
## Load and serve the modules | ||
|
||
```bash | ||
MESSAGE="💊 Capsule Rocks 🚀" ./capsule \ | ||
-wasm=./tmp/hello.wasm \ | ||
-url="http://localhost:4999/k33g/hello/0.0.0/hello.wasm" \ | ||
-mode=http \ | ||
-httpPort=9091 | ||
|
||
MESSAGE="💊 Capsule Rocks 🚀" ./capsule \ | ||
-wasm=./tmp/hey.wasm \ | ||
-url="http://localhost:4999/k33g/hey/0.0.0/hey.wasm" \ | ||
-mode=http \ | ||
-httpPort=9092 | ||
``` | ||
|
||
## Call the functions | ||
|
||
```bash | ||
curl -v -X POST \ | ||
http://localhost:9091 \ | ||
-H 'content-type: application/json; charset=utf-8' \ | ||
-d '{"message": "Golang 💚💜 wasm", "author": "Bob Morane"}' | ||
``` | ||
|
||
```bash | ||
curl -v -X POST \ | ||
http://localhost:9092 \ | ||
-H 'content-type: application/json; charset=utf-8' \ | ||
-d '{"message": "Golang 💚💜 wasm", "author": "Bill Murray"}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,8 @@ | ||
#!/bin/bash | ||
|
||
cd ../with-proxy/capsule-hello | ||
cd ./capsule-hello | ||
./build.sh | ||
|
||
cd ../capsule-hey | ||
./build.sh | ||
|
||
cd ../capsule-hola | ||
./build.sh | ||
|
||
cd ../capsule-hola-orange | ||
./build.sh | ||
|
||
cd ../capsule-hola-yellow | ||
./build.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
tinygo build -o hello.wasm -scheduler=none -target wasi ./hello.go | ||
|
||
ls -lh *.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module github.com/bots-garden/capsule/wasm_modules/registry-demo/capsule-hello | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/bots-garden/capsule/capsulemodule v0.0.0-20220815092415-964aa3e0fdc2 | ||
github.com/tidwall/gjson v1.14.2 | ||
github.com/tidwall/sjson v1.2.5 | ||
) | ||
|
||
require ( | ||
github.com/bots-garden/capsule v0.0.0-20220815052111-84fb610d29f3 // indirect | ||
github.com/tidwall/match v1.1.1 // indirect | ||
github.com/tidwall/pretty v1.2.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
github.com/bots-garden/capsule v0.0.0-20220815052111-84fb610d29f3 h1:jd6GhVtU6hJh2YhTOal46CxbSfGALQOw+QdwC4N/7eg= | ||
github.com/bots-garden/capsule v0.0.0-20220815052111-84fb610d29f3/go.mod h1:PBhXY24j6vjuYghjEt+9mXzDb2ZwD9m9PAh9e6FTXck= | ||
github.com/bots-garden/capsule/capsulemodule v0.0.0-20220815092415-964aa3e0fdc2 h1:SfgCTdHbmOkcrxlgvdjJiQaue9LsxAW6doCGOI2wxBE= | ||
github.com/bots-garden/capsule/capsulemodule v0.0.0-20220815092415-964aa3e0fdc2/go.mod h1:tu9DYBPXGSfiDaCN1opAFZZ3FFt3TVFH5jkYnPypY64= | ||
github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo= | ||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= | ||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | ||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= | ||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= | ||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= | ||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= | ||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
// TinyGo wasm module | ||
import ( | ||
hf "github.com/bots-garden/capsule/capsulemodule/hostfunctions" | ||
/* string to json */ | ||
"github.com/tidwall/gjson" | ||
/* create json string */ | ||
"github.com/tidwall/sjson" | ||
) | ||
|
||
// main is required. | ||
func main() { | ||
|
||
hf.SetHandleHttp(Handle) | ||
} | ||
|
||
func Handle(bodyReq string, headersReq map[string]string) (bodyResp string, headersResp map[string]string, errResp error) { | ||
/* | ||
bodyReq = {"author":"Philippe","message":"Golang 💚 wasm"} | ||
*/ | ||
hf.Log("📝 body: " + bodyReq) | ||
|
||
author := gjson.Get(bodyReq, "author") | ||
message := gjson.Get(bodyReq, "message") | ||
hf.Log("👋 " + message.String() + " by " + author.String() + " 😄") | ||
|
||
hf.Log("Content-Type: " + headersReq["Content-Type"]) | ||
hf.Log("Content-Length: " + headersReq["Content-Length"]) | ||
hf.Log("User-Agent: " + headersReq["User-Agent"]) | ||
|
||
envMessage, err := hf.GetEnv("MESSAGE") | ||
if err != nil { | ||
hf.Log("😡 " + err.Error()) | ||
} else { | ||
hf.Log("Environment variable: " + envMessage) | ||
} | ||
|
||
headersResp = map[string]string{ | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Message": "👋 hello world 🌍", | ||
} | ||
|
||
jsondoc := `{"message": "", "author": ""}` | ||
jsondoc, _ = sjson.Set(jsondoc, "message", "👋 Hello! What's up?") | ||
jsondoc, _ = sjson.Set(jsondoc, "author", "Bob") | ||
|
||
return jsondoc, headersResp, nil | ||
//return jsondoc, headersResp , errors.New("😡 oups I did it again") | ||
} | ||
|
||
// TODO: helpers: SetHeader() ... | ||
// TODO: be able to return a status code | ||
|
||
/* | ||
curl -v -X POST \ | ||
http://localhost:9091 \ | ||
-H 'content-type: application/json' \ | ||
-d '{"message": "Golang 💚 wasm"}' | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
curl -v -X POST \ | ||
http://localhost:9091 \ | ||
-H 'content-type: application/json; charset=utf-8' \ | ||
-d '{"message": "Golang 💚💜 wasm", "author": "Philippe"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
cd ../../../capsule-launcher | ||
|
||
export MESSAGE="💊 Capsule Rocks 🚀" | ||
go run main.go \ | ||
-wasm=../wasm_modules/registry-demo/capsule-hello/hello.wasm \ | ||
-mode=http \ | ||
-httpPort=9091 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
tinygo build -o hey.wasm -scheduler=none -target wasi ./hey.go | ||
|
||
ls -lh *.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module github.com/bots-garden/capsule/wasm_modules/registry-demo/capsule-hey | ||
|
||
go 1.18 | ||
|
||
require ( | ||
github.com/bots-garden/capsule/capsulemodule v0.0.0-20220815092415-964aa3e0fdc2 | ||
github.com/tidwall/gjson v1.14.2 | ||
github.com/tidwall/sjson v1.2.5 | ||
) | ||
|
||
require ( | ||
github.com/bots-garden/capsule v0.0.0-20220815052111-84fb610d29f3 // indirect | ||
github.com/tidwall/match v1.1.1 // indirect | ||
github.com/tidwall/pretty v1.2.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
github.com/bots-garden/capsule v0.0.0-20220815052111-84fb610d29f3 h1:jd6GhVtU6hJh2YhTOal46CxbSfGALQOw+QdwC4N/7eg= | ||
github.com/bots-garden/capsule v0.0.0-20220815052111-84fb610d29f3/go.mod h1:PBhXY24j6vjuYghjEt+9mXzDb2ZwD9m9PAh9e6FTXck= | ||
github.com/bots-garden/capsule/capsulemodule v0.0.0-20220815092415-964aa3e0fdc2 h1:SfgCTdHbmOkcrxlgvdjJiQaue9LsxAW6doCGOI2wxBE= | ||
github.com/bots-garden/capsule/capsulemodule v0.0.0-20220815092415-964aa3e0fdc2/go.mod h1:tu9DYBPXGSfiDaCN1opAFZZ3FFt3TVFH5jkYnPypY64= | ||
github.com/tidwall/gjson v1.14.2 h1:6BBkirS0rAHjumnjHF6qgy5d2YAJ1TLIaFE2lzfOLqo= | ||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= | ||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= | ||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= | ||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= | ||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= | ||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= | ||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package main | ||
|
||
// TinyGo wasm module | ||
import ( | ||
hf "github.com/bots-garden/capsule/capsulemodule/hostfunctions" | ||
/* string to json */ | ||
"github.com/tidwall/gjson" | ||
/* create json string */ | ||
"github.com/tidwall/sjson" | ||
) | ||
|
||
// main is required. | ||
func main() { | ||
|
||
hf.SetHandleHttp(Handle) | ||
} | ||
|
||
func Handle(bodyReq string, headersReq map[string]string) (bodyResp string, headersResp map[string]string, errResp error) { | ||
/* | ||
bodyReq = {"author":"Philippe","message":"Golang 💚 wasm"} | ||
*/ | ||
hf.Log("📝 body: " + bodyReq) | ||
|
||
author := gjson.Get(bodyReq, "author") | ||
message := gjson.Get(bodyReq, "message") | ||
hf.Log("👋 " + message.String() + " by " + author.String() + " 😄") | ||
|
||
hf.Log("Content-Type: " + headersReq["Content-Type"]) | ||
hf.Log("Content-Length: " + headersReq["Content-Length"]) | ||
hf.Log("User-Agent: " + headersReq["User-Agent"]) | ||
|
||
envMessage, err := hf.GetEnv("MESSAGE") | ||
if err != nil { | ||
hf.Log("😡 " + err.Error()) | ||
} else { | ||
hf.Log("Environment variable: " + envMessage) | ||
} | ||
|
||
headersResp = map[string]string{ | ||
"Content-Type": "application/json; charset=utf-8", | ||
"Message": "👋 hey people 🌍", | ||
} | ||
|
||
jsondoc := `{"message": "", "author": ""}` | ||
jsondoc, _ = sjson.Set(jsondoc, "message", "👋 Hey! What's up?") | ||
jsondoc, _ = sjson.Set(jsondoc, "author", "Bob") | ||
|
||
return jsondoc, headersResp, nil | ||
//return jsondoc, headersResp , errors.New("😡 oups I did it again") | ||
} | ||
|
||
// TODO: helpers: SetHeader() ... | ||
// TODO: be able to return a status code | ||
|
||
/* | ||
curl -v -X POST \ | ||
http://localhost:9092 \ | ||
-H 'content-type: application/json' \ | ||
-d '{"message": "Golang 💚 wasm"}' | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
curl -v -X POST \ | ||
http://localhost:9092 \ | ||
-H 'content-type: application/json; charset=utf-8' \ | ||
-d '{"message": "Golang 💚💜 wasm", "author": "Philippe"}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
cd ../../../capsule-launcher | ||
|
||
export MESSAGE="💊 Capsule is Amazing 😍" | ||
go run main.go \ | ||
-wasm=../wasm_modules/registry-demo/capsule-hey/hey.wasm \ | ||
-mode=http \ | ||
-httpPort=9092 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
cd ../../capsule-launcher | ||
|
||
export MESSAGE="💊 Capsule Rocks 🚀" | ||
go run main.go \ | ||
-wasm=./tmp/hello.wasm \ | ||
-url="http://localhost:4999/k33g/hello/0.0.0/hello.wasm" \ | ||
-mode=http \ | ||
-httpPort=9091 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
cd ../../capsule-launcher | ||
|
||
export MESSAGE="💊 Capsule Rocks 🚀" | ||
go run main.go \ | ||
-wasm=./tmp/hey.wasm \ | ||
-url="http://localhost:4999/k33g/hey/0.0.0/hey.wasm" \ | ||
-mode=http \ | ||
-httpPort=9092 | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
wasm_modules/registry-demo/publish-wasm-modules-to-registry.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
curl -X POST http://localhost:4999/upload/k33g/hello/0.0.0 \ | ||
-F "file=@./capsule-hello/hello.wasm" \ | ||
-F "info=hello function from @k33g" \ | ||
-H "Content-Type: multipart/form-data" | ||
|
||
curl -X POST http://localhost:4999/upload/k33g/hey/0.0.0 \ | ||
-F "file=@./capsule-hey/hey.wasm" \ | ||
-F "info=hello hey from @k33g" \ | ||
-H "Content-Type: multipart/form-data" |
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
wasm_modules/registry-demo/registry/functions/k33g/hello/0.0.0/hello.info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello function from @k33g |
Oops, something went wrong.