gpt4 book ai didi

heroku - 使用环境变量部署到 Heroku 按钮

转载 作者:行者123 更新时间:2023-12-01 13:35:10 25 4
gpt4 key购买 nike

我想向托管在 GitHub 上的应用程序添加一个“部署到 Heroku”按钮,但唯一的问题是它需要运行环境变量,并且需要用户输入它们才能工作。有没有办法在app.json模式在安装之前提示用户设置这些?或者我最好的选择是将它们设置为标准字符串,例如“replace_me”并告诉用户从那里在我的自述文件中输入他们的数据。

我看到你可以在他们的文档中生成一个“ secret ”,但我不确定这是否是我正在寻找的。

最佳答案

您可能已经发现了这一点,但看起来您在 app.json 架构中定义了 env 变量。 (这里有更详细的描述:https://blog.heroku.com/introducing_the_app_json_application_manifest)

他们提供的示例架构:

{
"name": "Ruby on Rails",
"description": "A template for getting started with the popular Ruby framework.",
"website": "http://rubyonrails.org",
"success_url": "/welcome",
"addons": ["heroku-postgresql:hobby-dev", "papertrail"],
"env": {
"RAILS_ENV": "production",
"COOKIE_SECRET": {
"description": "This gets generated",
"generator": "secret"
},
"SETUP_BY": {
"description": "Who initiated this setup",
"value": ""
}
},
"scripts": {
"postdeploy": "bundle exec rake db:migrate"
}
}

然后,当您访问此部署 URL 时,您将传入 app.json 文件所在的 Github 存储库的路径,以及 URL 中的任何硬编码 ENV 变量:
https://heroku.com/deploy?template=https://github.com/rauchg/slackin/tree/0.5.1& env[SLACK_SUBDOMAIN]=testdomain

当您访问该 URL 时,它会自动生成一个表单,提示您输入剩余的 env 值。

这是由我制作的应用程序配置生成的示例表单 here :

enter image description here

当应用程序部署时,它会将用户输入的值存储在正确的环境变量中。

关于heroku - 使用环境变量部署到 Heroku 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44026881/

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