ipld-eth-server/Gododir/main.go

114 lines
3.7 KiB
Go
Raw Normal View History

2017-11-01 14:40:04 +00:00
package main
import (
"log"
"fmt"
"github.com/8thlight/vulcanizedb/cmd"
2017-11-06 18:53:43 +00:00
"github.com/8thlight/vulcanizedb/pkg/config"
2017-11-01 14:40:04 +00:00
do "gopkg.in/godo.v2"
)
2017-11-02 22:37:27 +00:00
func parseEnvironment(context *do.Context) string {
environment := context.Args.MayString("", "environment", "env", "e")
if environment == "" {
log.Fatalln("--environment required")
}
2017-11-02 22:37:27 +00:00
return environment
}
2017-11-01 14:40:04 +00:00
func tasks(p *do.Project) {
2017-11-02 22:37:27 +00:00
p.Task("run", nil, func(context *do.Context) {
environment := parseEnvironment(context)
context.Start(`go run main.go --environment={{.environment}}`,
do.M{"environment": environment, "$in": "cmd/run"})
})
p.Task("vulcanizeDb", nil, func(context *do.Context) {
environment := parseEnvironment(context)
context.Start(`go run main.go --environment={{.environment}}`,
do.M{"environment": environment, "$in": "cmd/vulcanize_db"})
})
p.Task("populateBlocks", nil, func(context *do.Context) {
environment := parseEnvironment(context)
startingNumber := context.Args.MayInt(-1, "starting-number")
if startingNumber < 0 {
log.Fatalln("--starting-number required")
}
context.Start(`go run main.go --environment={{.environment}} --starting-number={{.startingNumber}}`,
do.M{"environment": environment, "startingNumber": startingNumber, "$in": "cmd/populate_blocks"})
})
p.Task("getLogs", nil, func(context *do.Context) {
environment := parseEnvironment(context)
contractHash := context.Args.MayString("", "contract-hash", "c")
if contractHash == "" {
log.Fatalln("--contract-hash required")
}
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}}`,
do.M{
"environment": environment,
"contractHash": contractHash,
"$in": "cmd/get_logs",
})
})
p.Task("watchContract", nil, func(context *do.Context) {
environment := parseEnvironment(context)
contractHash := context.Args.MayString("", "contract-hash", "c")
abiFilepath := context.Args.MayString("", "abi-filepath", "a")
if contractHash == "" {
log.Fatalln("--contract-hash required")
}
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --abi-filepath={{.abiFilepath}}`,
do.M{
"environment": environment,
"contractHash": contractHash,
"abiFilepath": abiFilepath,
"$in": "cmd/watch_contract",
})
})
2017-11-02 22:37:27 +00:00
p.Task("migrate", nil, func(context *do.Context) {
environment := parseEnvironment(context)
cfg := cmd.LoadConfig(environment)
2017-11-02 22:37:27 +00:00
connectString := config.DbConnectionString(cfg.Database)
2017-11-06 19:11:56 +00:00
migrate := fmt.Sprintf("migrate -database '%s' -path ./db/migrations up", connectString)
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > ./db/schema.sql", cfg.Database.Name)
2017-11-02 22:37:27 +00:00
context.Bash(migrate)
context.Bash(dumpSchema)
})
2017-11-02 22:37:27 +00:00
p.Task("rollback", nil, func(context *do.Context) {
environment := parseEnvironment(context)
cfg := cmd.LoadConfig(environment)
2017-11-02 22:37:27 +00:00
connectString := config.DbConnectionString(cfg.Database)
2017-11-06 19:11:56 +00:00
migrate := fmt.Sprintf("migrate -database '%s' -path ./db/migrations down 1", connectString)
dumpSchema := fmt.Sprintf("pg_dump -O -s %s > ./db/schema.sql", cfg.Database.Name)
2017-11-02 22:37:27 +00:00
context.Bash(migrate)
context.Bash(dumpSchema)
2017-11-01 14:40:04 +00:00
})
p.Task("showContractSummary", nil, func(context *do.Context) {
environment := parseEnvironment(context)
contractHash := context.Args.MayString("", "contract-hash", "c")
blockNumber := context.Args.MayInt(-1, "block-number", "b")
if contractHash == "" {
log.Fatalln("--contract-hash required")
}
context.Start(`go run main.go --environment={{.environment}} --contract-hash={{.contractHash}} --block-number={{.blockNumber}}`,
do.M{"environment": environment,
"contractHash": contractHash,
"blockNumber": blockNumber,
"$in": "cmd/show_contract_summary"})
})
2017-11-01 14:40:04 +00:00
}
func main() {
do.Godo(tasks)
}