Skip to content

Commit

Permalink
Pass substreams endpoint to service serve (#354)
Browse files Browse the repository at this point in the history
* `service serve`: fix endpoint handling
* add flag to serve command
  • Loading branch information
YaroShkvorets authored Dec 14, 2023
1 parent 217d8cf commit 8a5f8ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion cmd/substreams/service-serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
func init() {
serviceCmd.AddCommand(serveCmd)

serveCmd.Flags().StringP("endpoint", "e", "", "Substreams endpoint to connect to")
serveCmd.Flags().String("data-dir", "./sink-data", "Store data to this folder")
serveCmd.Flags().String("listen-addr", "localhost:8000", "Listen for GRPC connections on this address")
serveCmd.Flags().String("cors-host-regex-allow", "^localhost", "Regex to allow CORS origin requests from, defaults to localhost only")
Expand Down Expand Up @@ -52,6 +53,7 @@ func serveE(cmd *cobra.Command, args []string) error {
listenAddr := sflags.MustGetString(cmd, "listen-addr")
corsHostRegexAllow := sflags.MustGetString(cmd, "cors-host-regex-allow")
dataDir := sflags.MustGetString(cmd, "data-dir")
endpoint := sflags.MustGetString(cmd, "endpoint")

var cors *regexp.Regexp
if corsHostRegexAllow != "" {
Expand All @@ -72,7 +74,7 @@ func serveE(cmd *cobra.Command, args []string) error {
var err error
switch engineType {
case "docker":
engine, err = docker.NewEngine(dataDir, token)
engine, err = docker.NewEngine(dataDir, token, endpoint)
if err != nil {
return err
}
Expand Down
14 changes: 8 additions & 6 deletions sink-server/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ import (
)

type DockerEngine struct {
mutex sync.Mutex
dir string
token string
mutex sync.Mutex
dir string
endpoint string
token string
}

func NewEngine(dir string, sf_token string) (*DockerEngine, error) {
func NewEngine(dir string, sf_token string, endpoint string) (*DockerEngine, error) {
out := &DockerEngine{
dir: dir,
token: sf_token,
dir: dir,
token: sf_token,
endpoint: endpoint,
}
if err := out.CheckVersion(); err != nil {
return nil, err
Expand Down
9 changes: 7 additions & 2 deletions sink-server/docker/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,20 @@ func (e *DockerEngine) newSink(deploymentID string, dbService string, pkg *pbsub
withPostgraphile = "--postgraphile"
}

withEndpoint := ""
if e.endpoint != "" {
withEndpoint = "-e " + e.endpoint
}

startScript := []byte(fmt.Sprintf(`#!/bin/bash
set -xeu
if [ ! -f /opt/subservices/data/setup-complete ]; then
/app/substreams-sink-sql setup $DSN /opt/subservices/config/substreams.spkg %s && touch /opt/subservices/data/setup-complete
fi
/app/substreams-sink-sql run $DSN /opt/subservices/config/substreams.spkg --on-module-hash-mistmatch=warn
`, withPostgraphile))
/app/substreams-sink-sql run $DSN /opt/subservices/config/substreams.spkg --on-module-hash-mistmatch=warn %s
`, withPostgraphile, withEndpoint))
if err := os.WriteFile(filepath.Join(configFolder, "start.sh"), startScript, 0755); err != nil {
fmt.Println("")
return conf, motd, fmt.Errorf("writing file: %w", err)
Expand Down

0 comments on commit 8a5f8ce

Please sign in to comment.