From bd3afb160f285779ce3dfb4df632ae96b6371ec7 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Thu, 21 Jun 2018 17:36:10 -0400 Subject: [PATCH] Because of the way we were making built binaries act as Buffalo binaries is was possible for this to result in database drivers loading twice and the app panicing. --- buffalo/cmd/build/build-packr.go | 2 +- buffalo/cmd/build/templates/main.go.tmpl | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/buffalo/cmd/build/build-packr.go b/buffalo/cmd/build/build-packr.go index 2dbf7a938..9bf51cd9d 100644 --- a/buffalo/cmd/build/build-packr.go +++ b/buffalo/cmd/build/build-packr.go @@ -8,5 +8,5 @@ import "github.com/gobuffalo/packr" // and any other packr generated files. func init() { packr.PackJSONBytes("./templates", "a.go.tmpl", "\"cGFja2FnZSBhCgppbXBvcnQgKAogICJsb2ciCiAgInN0cmluZ3MiCiAgImdpdGh1Yi5jb20vZ29idWZmYWxvL3BvcCIKICAiZ2l0aHViLmNvbS9tYXJrYmF0ZXMvaW5mbGVjdCIKICAiZ2l0aHViLmNvbS9nb2J1ZmZhbG8vcGFja3IiCiAgPCU9IGlmIChvcHRzLkVudmlyb25tZW50ICE9ICJkZXZlbG9wbWVudCIpIHsgJT4KICAiZ2l0aHViLmNvbS9nb2J1ZmZhbG8vZW52eSIKICA8JSB9ICU+CikKCmZ1bmMgaW5pdCgpIHsKICA8JT0gaWYgKG9wdHMuRW52aXJvbm1lbnQgIT0gImRldmVsb3BtZW50IikgeyAlPgogIGlmIGVyciA6PSBlbnZ5Lk11c3RTZXQoIkdPX0VOViIsICI8JT0gb3B0cy5FbnZpcm9ubWVudCAlPiIpOyBlcnIgIT0gbmlsIHsKICAgICAgbG9nLkZhdGFsKGVycikKICB9CiAgPCUgfSAlPgogIGRyb3BEYXRhYmFzZVltbCgpCgogIGJveCA6PSBwYWNrci5OZXdCb3goIi4vIikKICBpZiBib3guSGFzKCJpbmZsZWN0aW9ucy5qc29uIikgewogICAgciA6PSBzdHJp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pZiBlcnIgIT0gbmlsIHsKICAgICAgICBsb2cuRmF0YWwoZXJyKQogICAgICB9CiAgICB9CiAgICBjbWQgOj0gZXhlYy5Db21tYW5kKCJidWZmYWxvIiwgYXJnc1sxOl0uLi4pCiAgICBjbWQuU3RkaW4gPSBvcy5TdGRpbgogICAgY21kLlN0ZG91dCA9IG9zLlN0ZG91dAogICAgY21kLlN0ZGVyciA9IG9zLlN0ZGVycgogICAgZXJyIDo9IGNtZC5SdW4oKQogICAgaWYgZXJyICE9IG5pbCB7CiAgICAgIGxvZy5GYXRhbChlcnIpCiAgICB9CiAgfQp9CgpmdW5jIHByaW50VmVyc2lvbigpIHsKICBmbXQuUHJpbnRmKCI8JT0gb3B0cy5OYW1lLlRpdGxlKCkgJT4gdmVyc2lvbiAlc1xuIiwgcnVudGltZS5CdWlsZCgpKQp9Cgo8JT0gaWYgKG9wdHMuV2l0aFBvcCkgeyAlPgpmdW5jIG1pZ3JhdGUoKSB7CiAgYm94LCBlcnIgOj0gcG9wLk5ld01pZ3JhdGlvbkJveChwYWNrci5OZXdCb3goIi4vbWlncmF0aW9ucyIpLCBtb2RlbHMuREIpCiAgaWYgZXJyICE9IG5pbCB7CiAgICBsb2cuRmF0YWxmKCJGYWlsZWQgdG8gdW5wYWNrIG1pZ3JhdGlvbnM6ICVzIiwgZXJyKQogIH0KICBlcnIgPSBib3guVXAoKQogIGlmIGVyciAhPSBuaWwgewogICAgbG9nLkZhdGFsZigiRmFpbGVkIHRvIHJ1biBtaWdyYXRpb25zOiAlcyIsIGVycikKICB9Cn0KPCUgfSAlPgo=\"") } diff --git a/buffalo/cmd/build/templates/main.go.tmpl b/buffalo/cmd/build/templates/main.go.tmpl index 45e84f653..aaa959fcb 100644 --- a/buffalo/cmd/build/templates/main.go.tmpl +++ b/buffalo/cmd/build/templates/main.go.tmpl @@ -4,11 +4,11 @@ import ( "fmt" "log" "os" + "os/exec" "time" "strings" "github.com/markbates/grift/grift" - "github.com/gobuffalo/buffalo/buffalo/cmd" "github.com/gobuffalo/buffalo/runtime" _ "<%= opts.PackagePkg %>/a" _ "<%= opts.ActionsPkg %>" @@ -64,7 +64,19 @@ func main() { log.Fatal(err) } default: - cmd.Execute() + if _, err := exec.LookPath("buffalo"); err != nil { + if err != nil { + log.Fatal(err) + } + } + cmd := exec.Command("buffalo", args[1:]...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + log.Fatal(err) + } } }