我想向托管在 GitHub 上的应用程序添加一个“部署到 Heroku”按钮,但唯一的问题是它需要运行环境变量,并且需要用户输入它们才能工作。app.json模式中有没有办法在安装之前提示用户进行设置?或者我最好的选择是将它们设置为标准字符串,例如“replace_me”并告诉用户从那里在我的自述文件中输入他们的数据。
我看到你可以在他们的文档中生成一个“秘密”,但我不确定这是否是我正在寻找的。
您可能已经发现了这一点,但看起来您在 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"
}
}
Run Code Online (Sandbox Code Playgroud)
然后,当您访问此部署 URL 时,您将传入 app.json 文件所在的 Github 存储库的路径,以及 URL 中的任何硬编码 ENV 变量:
https://heroku.com/deploy?template=https://github.com/rauchg/slackin/tree/0.5.1& env[SLACK_SUBDOMAIN]=testdomain
Run Code Online (Sandbox Code Playgroud)
当您访问该 URL 时,它会自动生成一个表单,提示您输入剩余的 env 值。
这是我在此处制作的应用程序配置生成的示例表单:
当应用程序部署时,它会将用户输入的值存储在正确的环境变量中。