亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Heroku 中獲取 golang-buildpack 的鉤子腳本中的環境變量?

如何在 Heroku 中獲取 golang-buildpack 的鉤子腳本中的環境變量?

Go
繁星coding 2022-06-13 15:36:20
當我為數據庫遷移構建自動化腳本時,我遇到了一個非常奇怪的問題。我按照官方文檔:預/后編譯鉤子如果文件 bin/go-pre-compile 或 bin/go-post-compile 存在并且可執行,那么它將在 repo 編譯之前(go-pre-compile)或編譯之后(go-post-compile)執行)。因為 buildpack 將編譯后的可執行文件安裝到 bin 中,所以 go-post-compile 鉤子可以在 go 中編寫,如果它是由指定的(見上文)安裝的。然后我制作了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 hookremote: app_uri: remote: database_url: ?sslmode=requireremote: panic: runtime error: invalid memory address or nil pointer dereferenceremote: [signal SIGSEGV: segmentation violation code=0x1 addr=0x58 pc=0x503b06]remote: go-post-compile似乎該進程在運行腳本時無法獲取環境變量。在 buildpack 編譯應用程序后,該過程與 config vars 配合得很好。那么你有什么想法嗎?
查看完整描述

1 回答

?
慕碼人2483693

TA貢獻1860條經驗 獲得超9個贊

經過一番研究,我找到了運行數據庫遷移自動化的解決方案。release phase開發人員應該在 Heroku中運行這些類型的命令。可以查看官方文檔:https ://devcenter.heroku.com/articles/release-phase


查看完整回答
反對 回復 2022-06-13
  • 1 回答
  • 0 關注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號