gpt4 book ai didi

database - 如何在 Heroku 中获取 golang-buildpack 的钩子(Hook)脚本中的环境变量?

转载 作者:行者123 更新时间:2023-12-01 22:22:06 24 4
gpt4 key购买 nike

当我为数据库迁移构建自动化脚本时,我遇到了一个非常奇怪的问题。我按照官方文档:

Pre/Post Compile Hooks

If the file bin/go-pre-compile or bin/go-post-compile exists and is executable then it will be executed either before compilation (go-pre-compile) of the repo, or after compilation (go-post-compile).

Because the buildpack installs compiled executables to bin, the go-post-compile hook can be written in go if it's installed by the specified (see above).


然后我制作了 go-post-compile下面的脚本:
var (
appURI := os.Getenv("APP_URI")
databaseURL := os.Getenv("DATABASE_URL")
)

func main() {
fmt.Printf("app_uri: %s\n", appURI)
fmt.Printf("database_url: %s\n", databaseURL)
sourcePath := fmt.Sprintf("file://%s/db/migrations", appURI)
m, err := migrate.New(sourcePath, databaseURL)
if err != nil {
logger.Error("Failed to establish the connection of the migration.", err)
}
err = m.Up()
if err != nil && err.Error() == "no change" {
fmt.Println(" > NOTE: There is no change related to the operation of the migration.")
return
} else if err != nil {
logger.Error("Failed to establish the connection of the migration.", err)
}
fmt.Println(" > Done.")
}
当我将代码推送到heroku时,出现以下错误:
remote: -----> Running bin/go-post-compile hook
remote: app_uri:
remote: database_url: ?sslmode=require
remote: panic: runtime error: invalid memory address or nil pointer dereference
remote: [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x503b06]
remote:
似乎进程在运行 go-post-compile时无法获取环境变量脚本。
在 buildpack 编译应用程序后,该过程与 config vars 配合得很好。
那么你有什么想法吗?

最佳答案

经过一番研究,我找到了运行数据库迁移自动化的解决方案。开发者应该在 release phase 中运行这些类型的命令。在赫罗库。可以查看官方文档:https://devcenter.heroku.com/articles/release-phase

关于database - 如何在 Heroku 中获取 golang-buildpack 的钩子(Hook)脚本中的环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62587937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com