/
deploy.go
61 lines (48 loc) · 1.71 KB
/
deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cli
import (
"fmt"
_ "net/http/pprof"
_ "github.com/lib/pq"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/streamingfast/sparkle/deployment"
"github.com/streamingfast/sparkle/storage/postgres"
"github.com/streamingfast/sparkle/subgraph"
"go.uber.org/zap"
)
var deployCmd = &cobra.Command{
Use: "deploy <subgraph-name>",
Short: "Deploy a new subgraph on the given database",
Args: cobra.ExactArgs(1),
RunE: runDeploy,
}
func init() {
deployCmd.Flags().String("psql-dsn", "postgresql://postgres:${PG_PASSWORD}@127.0.0.1:5432/graph-node?enable_incremental_sort=off&sslmode=disable", "Postgres DSN where to connect, expands environment variable in the form '${}'")
deployCmd.Flags().String("ipfs-address", "http://localhost:5001", "IPFS server to upload manfiest")
RootCmd.AddCommand(deployCmd)
}
func runDeploy(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
subgraphName := args[0]
psqlDSN := viper.GetString("deploy-cmd-psql-dsn")
ipfsAddr := viper.GetString("deploy-cmd-ipfs-address")
zlog.Info("starting subgraph deploy",
zap.String("psql_dsn", psqlDSN),
zap.String("subgraph_name", subgraphName),
zap.String("ipfs_address", ipfsAddr),
)
postgresDSN, err := postgres.ParseDSN(psqlDSN)
if err != nil {
return fmt.Errorf("invalid postgres DSN %q: %w", psqlDSN, err)
}
db, err := createPostgresDB(ctx, postgresDSN)
if err != nil {
return fmt.Errorf("creating postgres db: %w", err)
}
ipfsNode := deployment.NewIPFSNode(ipfsAddr)
if err := deployment.DeploySubgraph(ctx, db, subgraph.MainSubgraphDef, ipfsNode, subgraphName); err != nil {
return fmt.Errorf("deploying subgraph: %w", err)
}
zlog.Info("completed deployment of subgraph")
return nil
}