Skip to content

Commit

Permalink
skeleton for deployable substreams-based-subgraph in a box
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Oct 12, 2023
1 parent ff69904 commit 6edb1cb
Showing 1 changed file with 74 additions and 5 deletions.
79 changes: 74 additions & 5 deletions sink-server/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,7 @@ func (e *DockerEngine) Shutdown(zlog *zap.Logger) (err error) {
return err
}

func (e *DockerEngine) createManifest(deploymentID string, token string, pkg *pbsubstreams.Package) (content []byte, usedPorts []uint32, services map[string]string, runMeFirst []string, err error) {

if pkg.SinkConfig.TypeUrl != "sf.substreams.sink.sql.v1.Service" {
return nil, nil, nil, nil, fmt.Errorf("invalid sinkconfig type: %q. Only sf.substreams.sink.sql.v1.Service is supported for now.", pkg.SinkConfig.TypeUrl)
}
func (e *DockerEngine) createSQLManifest(deploymentID string, token string, pkg *pbsubstreams.Package) (content []byte, usedPorts []uint32, services map[string]string, runMeFirst []string, err error) {
sqlSvc := &pbsql.Service{}
if err := pkg.SinkConfig.UnmarshalTo(sqlSvc); err != nil {
return nil, nil, nil, nil, fmt.Errorf("cannot unmarshal sinkconfig: %w", err)
Expand Down Expand Up @@ -547,6 +543,79 @@ func (e *DockerEngine) createManifest(deploymentID string, token string, pkg *pb
content, err = yaml.Marshal(config)
return

}

func (e *DockerEngine) createSubgraphManifest(deploymentID string, token string, pkg *pbsubstreams.Package) (content []byte, usedPorts []uint32, services map[string]string, runMeFirst []string, err error) {

//
subgraphSvc := &pbsubgraph.Service{}

if err := pkg.SinkConfig.UnmarshalTo(sqlSvc); err != nil {
return nil, nil, nil, nil, fmt.Errorf("cannot unmarshal sinkconfig: %w", err)
}

services = make(map[string]string)

pg, pgMotd, err := e.newPostgres(deploymentID, pkg)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("creating postgres deployment: %w", err)
}

// FIXME: need IPFS
//ipfs, ipfsMotd, err := e.newIPFS()

runMeFirst = append(runMeFirst, pg.Name, ipfs.Name)

// note: graphnode is the sink
graphnode, graphnodeMotd, err := e.newGraphnode(deploymentID, pkg, pg.Name, ipfs.Name)
//pg, pgMotd, err := e.newPostgres(deploymentID, pkg)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("creating postgres deployment: %w", err)
}
services[graphnode.Name] = graphnodeMotd

config := types.Config{
Version: "3",
Services: []types.ServiceConfig{
pg,
ipfs,
graphnode,
},
}

if sqlSvc.PgwebFrontend != nil && sqlSvc.PgwebFrontend.Enabled {
pgweb, motd := e.newPGWeb(deploymentID, pg.Name)
services[pgweb.Name] = motd
config.Services = append(config.Services, pgweb)
}

if sqlSvc.PostgraphileFrontend != nil && sqlSvc.PostgraphileFrontend.Enabled {
postgraphile, motd := e.newPostgraphile(deploymentID, pg.Name)
services[postgraphile.Name] = motd
config.Services = append(config.Services, postgraphile)
}

for _, svc := range config.Services {
for _, port := range svc.Ports {
usedPorts = append(usedPorts, port.Published)
}
}

content, err = yaml.Marshal(config)
return

}

func (e *DockerEngine) createManifest(deploymentID string, token string, pkg *pbsubstreams.Package) (content []byte, usedPorts []uint32, services map[string]string, runMeFirst []string, err error) {

switch pkg.SinkConfig.TypeUrl {
case "sf.substreams.sink.sql.v1.Service":
return e.createSQLManifest(deploymentID, token, pkg)
case "sf.substreams.sink.subgraph.v1.Service":
return e.createSubgraphManifest(deploymentID, token, pkg)
default:
return nil, nil, nil, nil, fmt.Errorf("invalid sinkconfig type: %q. Only sf.substreams.sink.sql.v1.Service and sf.substreams.sink.subgraph.v1.Service are supported for now.", pkg.SinkConfig.TypeUrl)
}
// clickhouse:
// container_name: clickhouse-ssp
// image: clickhouse/clickhouse-server
Expand Down

0 comments on commit 6edb1cb

Please sign in to comment.