diff --git a/Makefile b/Makefile index 1ecde3a..0eb7aa0 100644 --- a/Makefile +++ b/Makefile @@ -4,12 +4,12 @@ PROTO_PATH := "../../go/pkg/mod/github.com/anthdm/hollywood@v0.0.0-2023123011010 build: @go build -o bin/api cmd/api/main.go - @go build -o bin/wasmserver cmd/wasmserver/main.go + @go build -o bin/ingress cmd/ingress/main.go @go build -o bin/raptor cmd/cli/main.go @go build -o bin/runtime cmd/runtime/main.go -wasmserver: build - @./bin/wasmserver +ingress: build + @./bin/ingress runtime: build @./bin/runtime diff --git a/cmd/api/main.go b/cmd/api/main.go index 4827f4a..63a2ff6 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -50,8 +50,8 @@ func main() { } server := api.NewServer(store, store, modCache) - fmt.Printf("api server running\t%s\n", config.GetApiUrl()) - log.Fatal(server.Listen(config.Get().APIServerAddr)) + fmt.Printf("api server running\t%s\n", config.ApiUrl()) + log.Fatal(server.Listen(config.Get().HTTPAPIAddr)) } func seedEndpoint(store storage.Store, cache storage.ModCacher) { @@ -81,7 +81,7 @@ func seedEndpoint(store storage.Store, cache storage.ModCacher) { if err != nil { log.Fatal(err) } - fmt.Printf("endpoint seeded: %s/live/%s\n", config.GetWasmUrl(), endpoint.ID) + fmt.Printf("endpoint seeded: %s/live/%s\n", config.IngressUrl(), endpoint.ID) } func compile(ctx context.Context, cache wazero.CompilationCache, blob []byte) { diff --git a/cmd/cli/main.go b/cmd/cli/main.go index bd5d66d..c92857d 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -61,7 +61,7 @@ func main() { printUsage() } - c := client.New(client.NewConfig().WithURL(config.GetApiUrl())) + c := client.New(client.NewConfig().WithURL(config.ApiUrl())) command := command{ client: c, } @@ -175,7 +175,7 @@ func (c command) handleDeploy(args []string) { } fmt.Println(string(b)) fmt.Println() - fmt.Printf("deploy preview: %s/preview/%s\n", config.GetWasmUrl(), deploy.ID) + fmt.Printf("deploy preview: %s/preview/%s\n", config.IngressUrl(), deploy.ID) } func (c command) handleServeEndpoint(args []string) { diff --git a/cmd/wasmserver/main.go b/cmd/ingress/main.go similarity index 74% rename from cmd/wasmserver/main.go rename to cmd/ingress/main.go index 3244650..81efe4f 100644 --- a/cmd/wasmserver/main.go +++ b/cmd/ingress/main.go @@ -16,13 +16,21 @@ import ( ) func main() { - var configFile string - flagSet := flag.NewFlagSet("raptor", flag.ExitOnError) + var ( + configFile string + address string + id string + region string + ) + + flagSet := flag.NewFlagSet("ingress", flag.ExitOnError) flagSet.StringVar(&configFile, "config", "config.toml", "") + flagSet.StringVar(&address, "cluster-addr", "127.0.0.1:8132", "") + flagSet.StringVar(&id, "id", "ingress", "") + flagSet.StringVar(®ion, "region", "default", "") flagSet.Parse(os.Args[1:]) - err := config.Parse(configFile) - if err != nil { + if err := config.Parse(configFile); err != nil { log.Fatal(err) } @@ -44,9 +52,9 @@ func main() { ) clusterConfig := cluster.NewConfig(). - WithListenAddr(config.Get().Cluster.Address). - WithRegion(config.Get().Cluster.Region). - WithID(config.Get().Cluster.ID) + WithListenAddr(address). + WithRegion(region). + WithID(id) c, err := cluster.New(clusterConfig) if err != nil { log.Fatal(err) @@ -58,13 +66,13 @@ func main() { c.Start() server := actrs.NewWasmServer( - config.Get().WASMServerAddr, + config.Get().HTTPIngressAddr, c, store, metricStore, modCache) c.Engine().Spawn(server, actrs.KindWasmServer) - fmt.Printf("wasm server running\t%s\n", config.Get().WASMServerAddr) + fmt.Printf("ingress server running\t%s\n", config.Get().HTTPIngressAddr) sigch := make(chan os.Signal, 1) signal.Notify(sigch, syscall.SIGINT, syscall.SIGTERM) diff --git a/cmd/runtime/main.go b/cmd/runtime/main.go index b01d4ab..5de0762 100644 --- a/cmd/runtime/main.go +++ b/cmd/runtime/main.go @@ -1,11 +1,13 @@ package main import ( + "flag" "log" "os" "os/signal" "syscall" + "github.com/anthdm/hollywood/actor" "github.com/anthdm/hollywood/cluster" "github.com/anthdm/raptor/internal/actrs" "github.com/anthdm/raptor/internal/config" @@ -13,9 +15,24 @@ import ( ) func main() { - if err := config.Parse("config.toml"); err != nil { + var ( + configFile string + address string + id string + region string + ) + + flagSet := flag.NewFlagSet("runtime", flag.ExitOnError) + flagSet.StringVar(&configFile, "config", "config.toml", "") + flagSet.StringVar(&address, "cluster-addr", "127.0.0.1:8134", "") + flagSet.StringVar(&id, "id", "runtime", "") + flagSet.StringVar(®ion, "region", "default", "") + flagSet.Parse(os.Args[1:]) + + if err := config.Parse(configFile); err != nil { log.Fatal(err) } + var ( user = config.Get().Storage.User pw = config.Get().Storage.Password @@ -33,17 +50,16 @@ func main() { // metricStore = store ) clusterConfig := cluster.NewConfig(). - WithListenAddr("127.0.0.1:6000"). - WithRegion("eu-west"). - WithID("member_2") + WithListenAddr(address). + WithRegion(region). + WithID(id) c, err := cluster.New(clusterConfig) if err != nil { log.Fatal(err) } c.RegisterKind(actrs.KindRuntime, actrs.NewRuntime(store, modCache), &cluster.KindConfig{}) - // c.Engine().Spawn(actrs.NewMetric, actrs.KindMetric, actor.WithID("1")) - // c.Engine().Spawn(actrs.NewRuntimeManager(c), actrs.KindRuntimeManager, actor.WithID("1")) - // c.Engine().Spawn(actrs.NewRuntimeLog, actrs.KindRuntimeLog, actor.WithID("1")) + c.Engine().Spawn(actrs.NewMetric, actrs.KindMetric, actor.WithID("1")) + c.Engine().Spawn(actrs.NewRuntimeLog, actrs.KindRuntimeLog, actor.WithID("1")) c.Start() sigch := make(chan os.Signal, 1) diff --git a/cmd/runtime/runtime.md b/cmd/runtime/runtime.md new file mode 100644 index 0000000..d3f500a --- /dev/null +++ b/cmd/runtime/runtime.md @@ -0,0 +1 @@ +# Runtime \ No newline at end of file diff --git a/internal/api/server.go b/internal/api/server.go index 4bb0d3d..41165ec 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -194,7 +194,7 @@ func (s *Server) handlePublish(w http.ResponseWriter, r *http.Request) error { resp := PublishResponse{ DeploymentID: deploy.ID, - URL: fmt.Sprintf("%s/live/%s", config.GetWasmUrl(), endpoint.ID), + URL: fmt.Sprintf("%s/live/%s", config.IngressUrl(), endpoint.ID), } return writeJSON(w, http.StatusOK, resp) } diff --git a/internal/config/config.go b/internal/config/config.go index 773c177..a4574b0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -9,17 +9,12 @@ import ( ) const defaultConfig = ` -wasmServerAddr = "127.0.0.1:5000" -apiServerAddr = "127.0.0.1:3000" -storageDriver = "sqlite" -apiToken = "foobarbaz" +httpIngressAddr = "127.0.0.1:5000" +httpAPIAddr = "127.0.0.1:3000" +storageDriver = "postgres" +apiToken = "" authorization = false -[cluster] -address = "127.0.0.1:6666" -id = "wasm_member_1" -region = "eu-west" - [storage] user = "postgres" password = "postgres" @@ -41,21 +36,13 @@ type Storage struct { SSLMode string } -type Cluster struct { - Address string - ID string - Region string -} - type Config struct { - APIServerAddr string - WASMServerAddr string - StorageDriver string - APIToken string - Authorization bool - - Storage Storage - Cluster Cluster + HTTPAPIAddr string + HTTPIngressAddr string + StorageDriver string + APIToken string + Authorization bool + Storage Storage } func Parse(path string) error { @@ -93,10 +80,10 @@ func makeURL(address string) string { return "http://" + net.JoinHostPort(host, port) } -func GetWasmUrl() string { - return makeURL(config.WASMServerAddr) +func IngressUrl() string { + return makeURL(config.HTTPIngressAddr) } -func GetApiUrl() string { - return makeURL(config.APIServerAddr) +func ApiUrl() string { + return makeURL(config.HTTPAPIAddr) }