This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from 8thlight/go-task
Add multiple environments
- Loading branch information
Showing
14 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
Gododir/godobin-* | ||
test_data_dir/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"fmt" | ||
|
||
cfg "github.com/8thlight/vulcanizedb/config" | ||
"github.com/8thlight/vulcanizedb/core" | ||
"github.com/jmoiron/sqlx" | ||
do "gopkg.in/godo.v2" | ||
) | ||
|
||
func parseIpcPath(context *do.Context) string { | ||
ipcPath := context.Args.MayString("", "ipc-path", "i") | ||
if ipcPath == "" { | ||
log.Fatalln("--ipc-path required") | ||
} | ||
return ipcPath | ||
} | ||
|
||
func startBlockchainListener(config cfg.Config, ipcPath string) { | ||
port := config.Database.Port | ||
host := config.Database.Hostname | ||
databaseName := config.Database.Name | ||
|
||
var blockchain core.Blockchain = core.NewGethBlockchain(ipcPath) | ||
blockchain.RegisterObserver(core.BlockchainLoggingObserver{}) | ||
pgConfig := fmt.Sprintf("host=%s port=%d dbname=%s sslmode=disable", host, port, databaseName) | ||
db, err := sqlx.Connect("postgres", pgConfig) | ||
if err != nil { | ||
log.Fatalf("Error connecting to DB: %v\n", err) | ||
} | ||
blockchain.RegisterObserver(core.BlockchainDBObserver{Db: db}) | ||
blockchain.SubscribeToEvents() | ||
} | ||
|
||
func tasks(p *do.Project) { | ||
|
||
p.Task("runPublic", nil, func(context *do.Context) { | ||
startBlockchainListener(cfg.Public(), parseIpcPath(context)) | ||
}) | ||
|
||
p.Task("runPrivate", nil, func(context *do.Context) { | ||
startBlockchainListener(cfg.Private(), parseIpcPath(context)) | ||
}) | ||
|
||
p.Task("migratePublic", nil, func(context *do.Context) { | ||
connectString := cfg.DbConnectionString(cfg.Public().Database) | ||
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations up", connectString)) | ||
context.Bash(fmt.Sprintf("pg_dump -O -s %s > migrations/schema.sql", cfg.Public().Database.Name)) | ||
}) | ||
|
||
p.Task("migratePrivate", nil, func(context *do.Context) { | ||
connectString := cfg.DbConnectionString(cfg.Private().Database) | ||
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations up", connectString)) | ||
context.Bash(fmt.Sprintf("pg_dump -O -s %s > migrations/schema.sql", cfg.Private().Database.Name)) | ||
}) | ||
|
||
p.Task("rollbackPublic", nil, func(context *do.Context) { | ||
connectString := cfg.DbConnectionString(cfg.Public().Database) | ||
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations down 1", connectString)) | ||
context.Bash("pg_dump -O -s vulcanize_public > migrations/schema.sql") | ||
}) | ||
|
||
p.Task("rollbackPrivate", nil, func(context *do.Context) { | ||
connectString := cfg.DbConnectionString(cfg.Private().Database) | ||
context.Bash(fmt.Sprintf("migrate -database '%s' -path ./migrations down 1", connectString)) | ||
context.Bash("pg_dump -O -s vulcanize_private > migrations/schema.sql") | ||
}) | ||
|
||
} | ||
|
||
func main() { | ||
do.Godo(tasks) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package config | ||
|
||
type Config struct { | ||
Database Database | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package config | ||
|
||
import "fmt" | ||
|
||
type Database struct { | ||
Hostname string | ||
Name string | ||
Port int | ||
} | ||
|
||
func DbConnectionString(dbConfig Database) string { | ||
return fmt.Sprintf("postgresql://%s:%d/%s?sslmode=disable", dbConfig.Hostname, dbConfig.Port, dbConfig.Name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package config | ||
|
||
func Private() Config { | ||
return Config{ | ||
Database: Database{ | ||
Name: "vulcanize_private", | ||
Hostname: "localhost", | ||
Port: 5432, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package config | ||
|
||
func Public() Config { | ||
return Config{ | ||
Database: Database{ | ||
Name: "vulcanize_public", | ||
Hostname: "localhost", | ||
Port: 5432, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.