如何使用秘密yaml配置文件部署heroku应用程序而不提交文件?
在其他rails项目中,我有一个本地database.yml,并且在源代码存储库中仅提交database.sample文件。部署时,一个 capistrano 脚本会将共享版本的 database.yml 符号链接到所有版本。
当部署到heroku时,使用git,它们似乎完全覆盖database.yml并执行内部操作。
对于database.yml来说这一切都很好,但是如果我在config/s3.yml中有s3配置怎么办?我将我的项目放在 github 上,所以我不想提交 s3.yml,让每个人都可以看到我的凭据。它宁愿提交一个示例 s3.sample,人们将用自己的设置覆盖它,并在我的工作目录中保留未提交的本地 s3.yml 文件。
处理这个问题的最佳方法是什么?
In other rails projects, I'd have a local database.yml and in source code repository only commit the database.sample file. When deploying, a capistrano script that would symlink a shared version of database.yml to all the releases.
When deploying to heroku, git is used and they seem to override database.yml altogether and do something internal.
That's all fine and good for database.yml, but what if I have s3 configurations in config/s3.yml. And I'm putting my project on github so I don't want to commit the s3.yml where everyone can see my credentials. It'd rather commit a sample s3.sample which people will override with their own settings, and keep a local s3.yml file uncommitted in my working directory.
what is the best way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
Heroku 对此有一些指导 -
http://devcenter.heroku.com/articles/config-vars< /a>
Heroku have some guidance on this -
http://devcenter.heroku.com/articles/config-vars
另一种解决方案是创建一个新的 local-branch ,在其中修改 .gitignore ,以便可以将 secret-file 推送到 heroku。
不要将此分支推送到您的 Github 存储库。
要将非主分支推送到heroku,请使用:
更多信息可以在以下位置找到:
https://devcenter.heroku.com /articles/multiple-environments#advanced-linking-local-branches-to-remote-apps
使用
heroku run bash
然后使用ls
检查你的秘密文件是否已被推送到herokuAn alternative solution is to create a new local-branch where you modify .gitignore so secret-file can be pushed to heroku.
DON'T push this branch to your Github repo.
To push non-master branch to heroku, use:
More info can be found on:
https://devcenter.heroku.com/articles/multiple-environments#advanced-linking-local-branches-to-remote-apps
Use
heroku run bash
and thenls
to check whether your secret-file have been pushed on to heroku or not将 s3 凭证存储在环境变量中。
在您的应用中:
请参阅 Heroku 配置变量文档,其中解释了开发设置等。
Store the s3 credentials in environment variables.
In your app:
See the Heroku Config Vars documentation which explain development setup etc.
如果使用 Rails 4.1 beta,请尝试来自 https://github.com/alexpeattie/heroku_secrets 的heroku_secrets gem:
这可以让你存储Rails 4.1 的 config/secrets.yml 中的密钥(未签入源代码管理),然后运行
以使其内容可供 heroku 使用(它会解析您的secrets.yml文件,并将其中的所有内容作为环境变量推送到heroku,根据heroku最佳实践文档)。
If using Rails 4.1 beta, try the heroku_secrets gem, from https://github.com/alexpeattie/heroku_secrets:
This lets you store secret keys in Rails 4.1's config/secrets.yml (which is not checked in to source control) and then just run
to make its contents available to heroku (it parses your secrets.yml file and pushes everything in it to heroku as environment variables, per the heroku best practice docs).
您还可以查看 Figaro gem。
You can also check out the Figaro gem.
我通过在构建期间从环境变量构建凭证来解决这个问题,并在创建 slug 之前将其写入我需要的位置。
您可能可以将一些特定于用例的信息转化为您的情况:
我正在部署一个 Node 项目,并在
postinstall
脚本的 package.json 中调用“bash create-secret.sh”。由于 postinstall 是在创建 slug 之前执行的,因此该文件将被添加到 slug 中。我不得不使用 bash 脚本,因为我在打印包含必须正确打印的换行符的字符串时遇到了一些麻烦,而且我无法使用 Node.js 来完成它。可能只是我不够熟练,但也许你遇到了类似的问题。
I solved this by building the credentials from env variables during the build time, and write it to where I need it to be before the slug is created.
Some usecase specific info that you can probably translate to your situation:
I'm deploying a Node project, and in the package.json in the
postinstall
script I call "bash create-secret.sh". Since postinstall is performed before the slug is created, the file will be added to the slug.I had to use a bash script because I had some trouble printing strings that contained newlines that had to be printed correctly, and I wasn't able to get it done with Node. Probably just me not being skilled enough, but maybe you run into a similar problem.
使用 Heroku + Build & 来研究这个问题部署时秘密。 Heroku 似乎不支持它。这意味着对于 Rails 应用程序,除了提交 BUNDLE_GITHUB__COM 之外别无选择,例如从私有存储库获取。
在向 heroku 发送消息之前,我会尝试看看是否有办法让 CI 捆绑私有 deps
Looking into this with Heroku + Build & Deploy-time Secrets. It seems like it's not something Heroku supports. This means for a rails app, there is no way other than committing BUNDLE_GITHUB__COM for example to get from private repo.
I'll try to see if there is a way to have CI bundle private deps before beaming at heroku