Skip to content

Commit

Permalink
πŸ“¦ create release v0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
k33g committed Oct 3, 2023
1 parent 5b664bb commit 56cad98
Show file tree
Hide file tree
Showing 25 changed files with 575 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ tmp
site
slingshot.code-workspace

linux
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
--input="πŸ€“ I'm a geek"
```

**Run Slingshot with Docker (multi arch image 🐳)**:
```bash title="Run Slingshot with Docker (multi arch image 🐳)"
HTTP_PORT=8080
docker run \
-p ${HTTP_PORT}:${HTTP_PORT} \
-v $(pwd)/hello-service:/app --rm botsgarden/slingshot:0.0.5 \
/slingshot start \
--wasm=./app/hello.wasm \
--handler=callHandler \
--http-port=${HTTP_PORT}
```

## How is Slingshot developed?

Slingshot is developed in Go with **[Wazero](https://wazero.io/)**[^1] as the Wasm runtime and **[Extism](https://extism.org/)**[^2], which offers a Wazero-based Go SDK and a Wasm plugin system.
Expand Down
11 changes: 11 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
--input="πŸ€“ I'm a geek"
```

```bash title="Run Slingshot with Docker (multi arch image 🐳)"
HTTP_PORT=8080
docker run \
-p ${HTTP_PORT}:${HTTP_PORT} \
-v $(pwd)/hello-service:/app --rm botsgarden/slingshot:0.0.5 \
/slingshot start \
--wasm=./app/hello.wasm \
--handler=callHandler \
--http-port=${HTTP_PORT}
```

## How is Slingshot developed?

Slingshot is developed in Go with **[Wazero](https://wazero.io/)**[^1] as the Wasm runtime and **[Extism](https://extism.org/)**[^2], which offers a Wazero-based Go SDK and a Wasm plugin system.
Expand Down
3 changes: 3 additions & 0 deletions examples-pdk/go/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.fontSize": 16,
}
37 changes: 4 additions & 33 deletions examples-pdk/go/02-hello-service/serve-with-docker.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
#!/bin/bash

operating_system=$(uname -o) # Darwin GNU/Linux
processor=$(uname -p) # x86_64 arm aarch64

if [ $operating_system == "GNU/Linux" ]; then
operating_system="linux"
fi

if [ $operating_system == "Darwin" ]; then
operating_system="darwin"
else
operating_system="linux"
fi

if [ $processor == "x86_64" ]; then
processor="amd64"
fi

if [ $processor == "arm" ]; then
processor="arm64"
fi

if [ $processor == "aarch64" ]; then
processor="arm64"
else
processor="amd64"
fi

rm slingshot

IMAGE_NAME="slingshot-${operating_system}-${processor}"
IMAGE_TAG="0.0.1"
DOCKER_USER="botsgarden"
IMAGE_NAME="slingshot"
IMAGE_TAG="0.0.5"
echo "πŸ–ΌοΈ ${IMAGE_NAME}"
HTTP_PORT="7070"

Expand All @@ -39,7 +10,7 @@ docker run \
-v $(pwd):/app --rm ${DOCKER_USER}/${IMAGE_NAME}:${IMAGE_TAG} \
/slingshot start \
--wasm=./app/hello.wasm \
--handler=handle \
--handler=callHandler \
--http-port=${HTTP_PORT}


2 changes: 2 additions & 0 deletions examples-pdk/go/14-input-string/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.wasm
slingshot
38 changes: 38 additions & 0 deletions examples-pdk/go/14-input-string/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'

description: >
task slingshot-build
task wasm-build
task wasm-run
tasks:
# task slingshot-build
slingshot-build:
cmds:
- |
target=$(pwd)
cd ../../../slingshot-server
env CGO_ENABLED=0 go build -ldflags="-s -w" -o ${target}/slingshot
# task wasm-build
wasm-build:
cmds:
- |
tinygo build -scheduler=none --no-debug \
-o input.wasm \
-target wasi main.go
ls -lh *.wasm
# task wasm-run
wasm-run:
cmds:
- |
./slingshot run --wasm=./input.wasm --handler=callHandler
# task all
all:
cmds:
- task slingshot-build
- task wasm-build
- task wasm-run
11 changes: 11 additions & 0 deletions examples-pdk/go/14-input-string/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module input-string

go 1.20

require github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e // indirect

require github.com/valyala/fastjson v1.6.4 // indirect

require github.com/bots-garden/slingshot/go-pdk v0.0.0

replace github.com/bots-garden/slingshot/go-pdk => ../../../go-pdk
5 changes: 5 additions & 0 deletions examples-pdk/go/14-input-string/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e h1:y6pBlzMRaYEBriiyzmT8e82927vBpum357VWi7Lg3/U=
github.com/extism/go-pdk v0.0.0-20230816024928-ee09fee7466e/go.mod h1:3qe+ObKvmOVwzmQDC5A7KzTuvfjImOnWsB1MWU6mWA4=
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ=
github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
20 changes: 20 additions & 0 deletions examples-pdk/go/14-input-string/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
slingshot "github.com/bots-garden/slingshot/go-pdk"
)

func helloHandler(argHandler []byte) {

name := slingshot.Input("πŸ€– What's your name? > ")

slingshot.Println("πŸ‘‹ Hello " + name + " πŸ˜„")

}

//export callHandler
func callHandler() {
slingshot.ExecVoidHandler(helloHandler)
}

func main() {}
3 changes: 3 additions & 0 deletions examples/go/12-input-string/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.wasm
slingshot
*.html
38 changes: 38 additions & 0 deletions examples/go/12-input-string/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3'

description: >
task slingshot-build
task wasm-build
task wasm-run
tasks:
# task slingshot-build
slingshot-build:
cmds:
- |
target=$(pwd)
cd ../../../slingshot-server
env CGO_ENABLED=0 go build -ldflags="-s -w" -o ${target}/slingshot
# task wasm-build
wasm-build:
cmds:
- |
tinygo build -scheduler=none --no-debug \
-o input.wasm \
-target wasi main.go
ls -lh *.wasm
# task wasm-run
wasm-run:
cmds:
- |
./slingshot run --wasm=./input.wasm --handler=hello
# task all
all:
cmds:
- task slingshot-build
- task wasm-build
- task wasm-run
3 changes: 3 additions & 0 deletions examples/go/12-input-string/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module input-string

go 1.20
36 changes: 36 additions & 0 deletions examples/go/12-input-string/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"github.com/extism/go-pdk"
)

//export hostPrintln
func hostPrintln(offset uint64) uint64

func Println(text string) {
memoryText := pdk.AllocateString(text)
hostPrintln(memoryText.Offset())
}

//export hostInput
func hostInput(offset uint64) uint64

func Input(prompt string) string {
promptMemory := pdk.AllocateString(prompt)
offset := hostInput(promptMemory.Offset())

memoryResult := pdk.FindMemory(offset)
buffResult := make([]byte, memoryResult.Length())
memoryResult.Load(buffResult)

return string(buffResult)
}

//export hello
func hello() {
name := Input("πŸ€– Name? > ")
Println("πŸ‘‹ Hello " + name + " πŸ˜ƒ")

}

func main() {}
1 change: 1 addition & 0 deletions examples/go/go.work
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use (
./09-nats-pub
./10-read
./11-write
./12-input-string
)

// go work sync
4 changes: 4 additions & 0 deletions examples/rust/12-input-string/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.wasm
slingshot*
target
index.html
Loading

0 comments on commit 56cad98

Please sign in to comment.