如何在Heroku预览应用程序postdeploy脚本中设置ENV var [英] How to set ENV var in Heroku preview app postdeploy script
问题描述
我想在预览应用程序上设置 HOST
env var to $ HEROKU_APP_NAME.herokuapps.com
它似乎不像我可以在 app.json
中执行此操作,因为这是一个计算值。
I want to set the HOST
env var to $HEROKU_APP_NAME.herokuapps.com
on a preview app. It doesn't look like I can do this in app.json
since this is a computed value.
我希望在这样的postdeploy脚本中执行此操作
I was hoping to do it in a "postdeploy" script like this
heroku config:set HOST="`heroku config:get HEROKU_APP_NAME -a neon-dev-pr-520`.herokuapps.com"
,但它希望以Heroku用户身份验证我。唉,这也不行:
but it wants to authenticate me as a Heroku user. Alas, this doesn't work either:
export HOST=$HEROKU_APP_NAME.herokuapps.com
任何建议?
推荐答案
我发现这篇文章,这表明你可以使用Heroku PlatformAPI。
I found this post which suggests that you can use the Heroku PlatformAPI.
在这种情况下,作为Rails Rake任务作为postdeploy运行:
In this case as a Rails Rake task which is run as the postdeploy:
desc 'Bootstrap review app'
task bootstrap: ['db:schema:load', 'db:seed'] do
heroku = PlatformAPI.connect_oauth(ENV['HEROKU_API_TOKEN'])
heroku.config_var.update(ENV['HEROKU_APP_NAME'], 'WWW_HOSTNAME' => "#{ENV['HEROKU_APP_NAME']}.herokuapp.com")
end
这篇关于如何在Heroku预览应用程序postdeploy脚本中设置ENV var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!