Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added runtime actor and removed chi from wasm server + fixed headers #7

Merged
merged 10 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
- name: Get Code
uses: actions/checkout@v4

- name: Build FFAAS
run: go build -o ./bin/ffaas ./cmd/ffaas/main.go
- name: Build
run: go build ./cmd/*

- name: Build Wasm
run: GOOS=wasip1 GOARCH=wasm go build -o examples/go/app.wasm examples/go/main.go
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
bin
ffaas.toml
config.toml
.db
.modcache
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
.PHONY: proto

build:
@go build -o bin/ffaas cmd/ffaas/main.go
@go build -o bin/api cmd/api/main.go
@go build -o bin/wasmserver cmd/wasmserver/main.go

wasmserver: build
@./bin/wasmserver

run: build
@./bin/ffaas --seed
api: build
@./bin/api --seed

test:
@go test ./pkg/* -v

proto:
protoc --go_out=. --go_opt=paths=source_relative --proto_path=. proto/types.proto

clean:
@rm -rf bin/ffaas

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# FFAAS
# Hailstorm
The distribute application runner powered by WASM.

Fast functions as a service platform powered by WASM.

coming soon...
# Installation
Documentation on how to run Hailstorm yourself is coming soon.

## API Server Endpoints

Expand Down
76 changes: 76 additions & 0 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package main

import (
"context"
"flag"
"fmt"
"log"
"os"
"time"

"github.com/anthdm/ffaas/pkg/api"
"github.com/anthdm/ffaas/pkg/config"
"github.com/anthdm/ffaas/pkg/storage"
"github.com/anthdm/ffaas/pkg/types"
"github.com/google/uuid"
"github.com/tetratelabs/wazero"
)

func main() {
var (
modCache = storage.NewDefaultModCache()
metricStore = storage.NewMemoryMetricStore()
configFile string
seed bool
)
flagSet := flag.NewFlagSet("ffaas", flag.ExitOnError)
flagSet.StringVar(&configFile, "config", "config.toml", "")
flagSet.BoolVar(&seed, "seed", false, "")
flagSet.Parse(os.Args[1:])

err := config.Parse(configFile)
if err != nil {
log.Fatal(err)
}

store, err := storage.NewRedisStore()
if err != nil {
log.Fatal(err)
}

if seed {
seedEndpoint(store, modCache)
}

server := api.NewServer(store, metricStore, modCache)
fmt.Printf("api server running\t%s\n", config.GetApiUrl())
log.Fatal(server.Listen(config.Get().APIServerAddr))
}

func seedEndpoint(store storage.Store, cache storage.ModCacher) {
b, err := os.ReadFile("examples/go/app.wasm")
if err != nil {
log.Fatal(err)
}
endpoint := &types.Endpoint{
ID: uuid.MustParse("09248ef6-c401-4601-8928-5964d61f2c61"),
Name: "Catfact parser",
Environment: map[string]string{"FOO": "bar"},
CreatedAT: time.Now(),
}

deploy := types.NewDeploy(endpoint, b)
endpoint.ActiveDeployID = deploy.ID
endpoint.URL = config.GetWasmUrl() + "/" + endpoint.ID.String()
endpoint.DeployHistory = append(endpoint.DeployHistory, deploy)
store.CreateEndpoint(endpoint)
store.CreateDeploy(deploy)
fmt.Printf("endpoint seeded: %s\n", endpoint.URL)
}

func compile(ctx context.Context, cache wazero.CompilationCache, blob []byte) {
config := wazero.NewRuntimeConfig().WithCompilationCache(cache)
runtime := wazero.NewRuntimeWithConfig(ctx, config)
defer runtime.Close(ctx)
runtime.CompileModule(ctx, blob)
}
91 changes: 0 additions & 91 deletions cmd/ffaas/main.go

This file was deleted.

63 changes: 63 additions & 0 deletions cmd/wasmserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"

"github.com/anthdm/ffaas/pkg/actrs"
"github.com/anthdm/ffaas/pkg/config"
"github.com/anthdm/ffaas/pkg/storage"
"github.com/anthdm/hollywood/actor"
"github.com/anthdm/hollywood/cluster"
"github.com/anthdm/hollywood/remote"
)

func main() {
var configFile string
flagSet := flag.NewFlagSet("ffaas", flag.ExitOnError)
flagSet.StringVar(&configFile, "config", "config.toml", "")
flagSet.Parse(os.Args[1:])

err := config.Parse(configFile)
if err != nil {
log.Fatal(err)
}

store, err := storage.NewRedisStore()
if err != nil {
log.Fatal(err)
}
var (
modCache = storage.NewDefaultModCache()
metricStore = storage.NewMemoryMetricStore()
)

remote := remote.New(config.Get().WASMClusterAddr, nil)
engine, err := actor.NewEngine(&actor.EngineConfig{
Remote: remote,
})
if err != nil {
log.Fatal(err)
}
// TODO: Get these values from the config.
c, err := cluster.New(cluster.Config{
Region: "f",
Engine: engine,
ID: "member1",
ClusterProvider: cluster.NewSelfManagedProvider(),
})
c.RegisterKind(actrs.KindRuntime, actrs.NewRuntime(store, modCache), &cluster.KindConfig{})
c.Start()

server := actrs.NewWasmServer(config.Get().WASMServerAddr, c, store, metricStore, modCache)
c.Engine().Spawn(server, actrs.KindWasmServer)
fmt.Printf("wasm server running\t%s\n", config.Get().WASMServerAddr)

sigch := make(chan os.Signal, 1)
signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM)
<-sigch
}
Binary file modified examples/go/app.wasm
Binary file not shown.
6 changes: 3 additions & 3 deletions examples/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package main

import (
"fmt"
"math/rand"
"net/http"
"os"

ffaas "github.com/anthdm/ffaas/sdk"
)

func myHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("the env:", os.Getenv("FOO"))
w.Write([]byte("from tinder swiper"))
num := rand.Intn(100)
w.Write([]byte(fmt.Sprintf("my first hailstorm app: %d", num)))
}

func main() {
Expand Down
20 changes: 19 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,36 @@ module github.com/anthdm/ffaas
go 1.21.0

require (
github.com/anthdm/hollywood v0.0.0-20231230200740-54133c9bd2b4
github.com/go-chi/chi/v5 v5.0.11
github.com/google/uuid v1.5.0
github.com/stealthrocket/net v0.2.1
github.com/stealthrocket/wasi-go v0.8.0
github.com/tetratelabs/wazero v1.5.0
github.com/vmihailenco/msgpack/v5 v5.4.1
google.golang.org/protobuf v1.30.0
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/planetscale/vtprotobuf v0.4.0 // indirect
github.com/redis/go-redis/v9 v9.3.1 // indirect
github.com/zeebo/errs v1.2.2 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.etcd.io/bbolt v1.3.8 // indirect
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
storj.io/drpc v0.0.32 // indirect
)

require (
github.com/pelletier/go-toml/v2 v2.1.1
github.com/stealthrocket/wazergo v0.19.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.14.0 // indirect
Expand Down
Loading
Loading