From 9ef1fda6677975ad1fd8b0d178a3c6d925c25337 Mon Sep 17 00:00:00 2001 From: Eric Meyer Date: Mon, 6 Nov 2017 11:40:52 -0600 Subject: [PATCH] Fix issue where godo would not build project * The solution is to add a main.go and call run * parses the current file contents --- Gododir/main.go | 28 ++-------------------------- cmd/run/main.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 cmd/run/main.go diff --git a/Gododir/main.go b/Gododir/main.go index 57a0f34e..caffb7d3 100644 --- a/Gododir/main.go +++ b/Gododir/main.go @@ -5,13 +5,7 @@ import ( "fmt" - "github.com/8thlight/vulcanizedb/blockchain_listener" "github.com/8thlight/vulcanizedb/config" - "github.com/8thlight/vulcanizedb/core" - "github.com/8thlight/vulcanizedb/geth" - "github.com/8thlight/vulcanizedb/observers" - "github.com/8thlight/vulcanizedb/repositories" - "github.com/jmoiron/sqlx" do "gopkg.in/godo.v2" ) @@ -23,30 +17,12 @@ func parseEnvironment(context *do.Context) string { return environment } -func startBlockchainListener(cfg config.Config) { - fmt.Println("Client Path ", cfg.Client.IPCPath) - blockchain := geth.NewGethBlockchain(cfg.Client.IPCPath) - loggingObserver := observers.BlockchainLoggingObserver{} - connectString := config.DbConnectionString(cfg.Database) - db, err := sqlx.Connect("postgres", connectString) - if err != nil { - log.Fatalf("Error connecting to DB: %v\n", err) - } - repository := repositories.NewPostgres(db) - dbObserver := observers.NewBlockchainDbObserver(repository) - listener := blockchain_listener.NewBlockchainListener(blockchain, []core.BlockchainObserver{ - loggingObserver, - dbObserver, - }) - listener.Start() -} - func tasks(p *do.Project) { p.Task("run", nil, func(context *do.Context) { environment := parseEnvironment(context) - cfg := config.NewConfig(environment) - startBlockchainListener(cfg) + context.Start(`go run main.go --environment={{.environment}}`, + do.M{"environment": environment, "$in": "cmd/run"}) }) p.Task("migrate", nil, func(context *do.Context) { diff --git a/cmd/run/main.go b/cmd/run/main.go new file mode 100644 index 00000000..57e3159e --- /dev/null +++ b/cmd/run/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "fmt" + "log" + + "flag" + + "github.com/8thlight/vulcanizedb/blockchain_listener" + "github.com/8thlight/vulcanizedb/config" + "github.com/8thlight/vulcanizedb/core" + "github.com/8thlight/vulcanizedb/geth" + "github.com/8thlight/vulcanizedb/observers" + "github.com/8thlight/vulcanizedb/repositories" + "github.com/jmoiron/sqlx" +) + +func main() { + environment := flag.String("environment", "", "Environment name") + flag.Parse() + cfg := config.NewConfig(*environment) + + fmt.Println("Client Path ", cfg.Client.IPCPath) + blockchain := geth.NewGethBlockchain(cfg.Client.IPCPath) + loggingObserver := observers.BlockchainLoggingObserver{} + connectString := config.DbConnectionString(cfg.Database) + db, err := sqlx.Connect("postgres", connectString) + if err != nil { + log.Fatalf("Error connecting to DB: %v\n", err) + } + repository := repositories.NewPostgres(db) + dbObserver := observers.NewBlockchainDbObserver(repository) + listener := blockchain_listener.NewBlockchainListener(blockchain, []core.BlockchainObserver{ + loggingObserver, + dbObserver, + }) + listener.Start() +}