Skip to content

Commit a6a4eb4

Browse files
committed
📦 create release v0.0.6
1 parent 56cad98 commit a6a4eb4

Some content is hidden

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

48 files changed

+485
-97
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ site
2121
slingshot.code-workspace
2222

2323
linux
24+
25+
localtonet

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SlingShot
22

3-
**SlingShot** is a **Wasm** runner to run or serve **[Extism](https://extism.org/)** **Wasm** plug-ins
3+
> How to run serverless applications augmented by Wasm
4+
5+
**SlingShot** is a **Wasm** runner to run or serve **[Extism](https://extism.org/)** **Wasm** plug-ins.
46

57
**Run a wasm plug-in**:
68
```bash title="Run a wasm plug-in"

docker-compose-demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.fontSize": 16,
3+
}

docker-compose-demo/compose.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
services:
2+
hello-world:
3+
image: "botsgarden/slingshot:0.0.5"
4+
command: |
5+
/slingshot start
6+
--wasm=./wasm-plugins/hello-service/hello.wasm
7+
--handler=handle
8+
--http-port=7071
9+
ports:
10+
- target: 7071
11+
published: 7071
12+
networks:
13+
- slingshot-net
14+
volumes:
15+
- ./wasm-plugins:/wasm-plugins
16+
17+
hey-people:
18+
image: "botsgarden/slingshot:0.0.5"
19+
command: |
20+
/slingshot start
21+
--wasm=./wasm-plugins/hey-service/hey.wasm
22+
--handler=handle
23+
--http-port=7072
24+
ports:
25+
- target: 7072
26+
published: 7072
27+
networks:
28+
- slingshot-net
29+
volumes:
30+
- ./wasm-plugins:/wasm-plugins
31+
32+
test-hello-service:
33+
image: yauritux/busybox-curl
34+
#image: ubuntu:latest
35+
depends_on:
36+
- hello-world
37+
networks:
38+
- slingshot-net
39+
command:
40+
- /bin/sh
41+
- -c
42+
- |
43+
curl http://hello-world:7071 \
44+
-H 'content-type: text/plain; charset=utf-8' \
45+
-d '😄 Bob Morane 🤖'
46+
47+
test-hey-service:
48+
image: yauritux/busybox-curl
49+
#image: ubuntu:latest
50+
depends_on:
51+
- hey-people
52+
networks:
53+
- slingshot-net
54+
command:
55+
- /bin/sh
56+
- -c
57+
- |
58+
curl http://hey-people:7072 \
59+
-H 'content-type: text/plain; charset=utf-8' \
60+
-d '😄 Bob Morane 🤖'
61+
62+
networks:
63+
slingshot-net:
64+
#driver: bridge
65+
#external: true

docker-compose-demo/go.work

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
go 1.20
2+
3+
use (
4+
./wasm-plugins/hello-service
5+
./wasm-plugins/hey-service
6+
)
7+
8+
// go work sync

docker-compose-demo/go.work.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e/go.mod h1:3qe+ObKvmOVwzmQDC5A7KzTuvfjImOnWsB1MWU6mWA4=
2+
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=

docker-compose-demo/query.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
curl --verbose \
4+
http://localhost:7071 \
5+
-H 'content-type: text/plain; charset=utf-8' \
6+
-d '😄 Bob Morane'
7+
echo ""
8+
9+
curl --verbose \
10+
http://localhost:7072 \
11+
-H 'content-type: text/plain; charset=utf-8' \
12+
-d '😄 Bob Morane'
13+
echo ""
14+
15+
16+
#curl http://198.19.249.146:7071 -H "content-type: text/plain; charset=utf-8" -d "😄 Bob Morane"
17+
#curl http://198.19.249.146:7072 -H "content-type: text/plain; charset=utf-8" -d "😄 Bob Morane"
18+
19+
curl https://hello-wasm.localto.net -H "content-type: text/plain; charset=utf-8" -d "😄 Bob Morane"
20+
21+
curl https://hello-one.localto.net -H "content-type: text/plain; charset=utf-8" -d "😄 Bob Morane"
22+
curl https://hello-two.localto.net -H "content-type: text/plain; charset=utf-8" -d "😄 Bob Morane"
23+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
DOCKER_USER="botsgarden"
3+
IMAGE_NAME="slingshot"
4+
IMAGE_TAG="0.0.5"
5+
echo "🖼️ ${IMAGE_NAME}"
6+
HTTP_PORT="7070"
7+
8+
#docker run \
9+
# -p ${HTTP_PORT}:${HTTP_PORT} \
10+
# -v $(pwd):/app --rm ${DOCKER_USER}/${IMAGE_NAME}:${IMAGE_TAG} \
11+
# /slingshot start \
12+
# --wasm=./app/hello.wasm \
13+
# --handler=callHandler \
14+
# --http-port=${HTTP_PORT}
15+
16+
docker run \
17+
-p ${HTTP_PORT}:${HTTP_PORT} \
18+
-v $(pwd):/app/wasm-plugins --rm ${DOCKER_USER}/${IMAGE_NAME}:${IMAGE_TAG} \
19+
/slingshot start \
20+
--wasm=./app/wasm-plugins/hello.wasm \
21+
--handler=handle \
22+
--http-port=${HTTP_PORT}

docker-compose-demo/start-docker.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
sudo chmod 666 /var/run/docker.sock
4+
ls -l /var/run/docker.sock
5+
sudo systemctl restart docker.service
6+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.wasm
2+
slingshot
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
tinygo build -scheduler=none --no-debug \
4+
-o hello.wasm \
5+
-target wasi main.go
6+
7+
ls -lh *.wasm
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module hello
2+
3+
go 1.20
4+
5+
require (
6+
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e
7+
github.com/valyala/fastjson v1.6.3
8+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e h1:y6pBlzMRaYEBriiyzmT8e82927vBpum357VWi7Lg3/U=
2+
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package main
2+
3+
import (
4+
"strings"
5+
6+
"github.com/extism/go-pdk"
7+
"github.com/valyala/fastjson"
8+
)
9+
10+
var parser = fastjson.Parser{}
11+
12+
//export handle
13+
func handle() {
14+
// read function argument from the memory
15+
http_request_data := pdk.Input()
16+
17+
var text string
18+
var code string
19+
20+
JSONData, err := parser.ParseBytes(http_request_data)
21+
if err != nil {
22+
text = "😡 Error: " + err.Error()
23+
code = "500"
24+
} else {
25+
text = "🩵 Hello " + string(JSONData.GetStringBytes("body"))
26+
code = "200"
27+
}
28+
29+
headers := []string{
30+
`"Content-Type": "application/json; charset=utf-8"`,
31+
`"X-Slingshot-version": "0.0.0"`,
32+
}
33+
34+
headersStr := strings.Join(headers, ",")
35+
36+
// if "Content-Type": "text/plain; charset=utf-8" => use textBody
37+
// if "Content-Type": "application/json; charset=utf-8" => use jsonBody
38+
39+
response := `{"headers":{` + headersStr + `}, "jsonBody": {"message":"` + text + `"}, "statusCode": `+ code +`}`
40+
41+
mem := pdk.AllocateString(response)
42+
// copy output to host memory
43+
pdk.OutputMemory(mem)
44+
}
45+
46+
func main() {}
47+
48+
//jsonBody
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
curl --verbose \
4+
http://localhost:7070 \
5+
-H 'content-type: text/plain; charset=utf-8' \
6+
-d '😄 Bob Morane'
7+
echo ""
8+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
DOCKER_USER="botsgarden"
3+
IMAGE_NAME="slingshot"
4+
IMAGE_TAG="0.0.5"
5+
echo "🖼️ ${IMAGE_NAME}"
6+
HTTP_PORT="7070"
7+
8+
docker run \
9+
-p ${HTTP_PORT}:${HTTP_PORT} \
10+
-v $(pwd):/app --rm ${DOCKER_USER}/${IMAGE_NAME}:${IMAGE_TAG} \
11+
/slingshot start \
12+
--wasm=./app/hello.wasm \
13+
--handler=handle \
14+
--http-port=${HTTP_PORT}
15+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.wasm
2+
slingshot
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
tinygo build -scheduler=none --no-debug \
4+
-o hey.wasm \
5+
-target wasi main.go
6+
7+
ls -lh *.wasm
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module hey
2+
3+
go 1.20
4+
5+
require (
6+
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e
7+
github.com/valyala/fastjson v1.6.3
8+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e h1:y6pBlzMRaYEBriiyzmT8e82927vBpum357VWi7Lg3/U=
2+
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"strings"
5+
6+
"github.com/extism/go-pdk"
7+
"github.com/valyala/fastjson"
8+
)
9+
10+
var parser = fastjson.Parser{}
11+
12+
//export handle
13+
func handle() {
14+
// read function argument from the memory
15+
http_request_data := pdk.Input()
16+
17+
var text string
18+
var code string
19+
20+
JSONData, err := parser.ParseBytes(http_request_data)
21+
if err != nil {
22+
text = "😡 Error: " + err.Error()
23+
code = "500"
24+
} else {
25+
text = "💜 Hey " + string(JSONData.GetStringBytes("body"))
26+
code = "200"
27+
}
28+
29+
headers := []string{
30+
`"Content-Type": "text/plain; charset=utf-8"`,
31+
`"X-Slingshot-version": "0.0.0"`,
32+
}
33+
34+
headersStr := strings.Join(headers, ",")
35+
36+
// if "Content-Type": "text/plain; charset=utf-8" => use textBody
37+
// if "Content-Type": "application/json; charset=utf-8" => use jsonBody
38+
39+
response := `{"headers":{` + headersStr + `}, "textBody": "` + text + `", "statusCode": `+ code +`}`
40+
41+
mem := pdk.AllocateString(response)
42+
// copy output to host memory
43+
pdk.OutputMemory(mem)
44+
}
45+
46+
func main() {}
47+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
curl --verbose \
4+
http://localhost:7070 \
5+
-H 'content-type: text/plain; charset=utf-8' \
6+
-d '😄 Bob Morane'
7+
echo ""
8+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
DOCKER_USER="botsgarden"
3+
IMAGE_NAME="slingshot"
4+
IMAGE_TAG="0.0.5"
5+
echo "🖼️ ${IMAGE_NAME}"
6+
HTTP_PORT="7070"
7+
8+
docker run \
9+
-p ${HTTP_PORT}:${HTTP_PORT} \
10+
-v $(pwd):/app --rm ${DOCKER_USER}/${IMAGE_NAME}:${IMAGE_TAG} \
11+
/slingshot start \
12+
--wasm=./app/hey.wasm \
13+
--handler=handle \
14+
--http-port=${HTTP_PORT}
15+

examples-pdk/go/02-hello-service/Taskfile.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ tasks:
5454
hey -n 300 -c 100 -m POST \
5555
-d '👋 John Doe' \
5656
"http://localhost:7070"
57+
58+
# task stress-report
59+
stress-report:
60+
cmds:
61+
- |
62+
hey -n 300 -c 100 -m POST \
63+
-d '👋 John Doe' \
64+
"http://localhost:7070" > $(./slingshot version).txt

examples-pdk/go/02-hello-service/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ func helloHandler(http_request_data []byte) []byte {
2828
}
2929

3030
headers := []string{
31-
`"Content-Type": "application/json; charset=utf-8"`,
31+
`"Content-Type": "text/plain; charset=utf-8"`,
3232
`"X-Slingshot-version": "0.0.0"`,
3333
}
3434

3535
headersStr := strings.Join(headers, ",")
3636

37+
// if "Content-Type": "text/plain; charset=utf-8" => use textBody
38+
// if "Content-Type": "application/json; charset=utf-8" => use jsonBody
39+
3740
response := `{"headers":{` + headersStr + `}, "textBody": "` + text + `", "statusCode": ` + code + `}`
3841

3942
return []byte(response)

0 commit comments

Comments
 (0)