Gemfile中的环境变量 [英] Environment variable in Gemfile
问题描述
我在Gemfile中使用环境变量时遇到问题。
我试图使用API密钥从私有Github存储库中加载gem:
I'm having trouble using an environment variable in my Gemfile.
I'm trying to load a gem from a private Github repository with an API key:
auth = ENV['SECRET_GIT']
gem 'foobar', git: "https://#{auth}:x-oauth-basic@github.com/Foo/Bar.git"
但是如果我 puts
我的 ENV ['SECRET_GIT']
变量,里面没有任何内容。
我虽然可以这样做,但由于这些(尤其是第一个):
- https://devcenter.heroku.com/articles/bundler-configuration#gem-source-username-and-password
-https://stackoverflow.com/a/7338154/5353193
-使用e部署到Heroku Gemfile中的环境变量
But if I puts
my ENV['SECRET_GIT']
variable, there's nothing in it.
I though you could do it this way because of these (especially the first one):
- https://devcenter.heroku.com/articles/bundler-configuration#gem-source-username-and-password
- https://stackoverflow.com/a/7338154/5353193
- Deploying to Heroku with environment variables in Gemfile
捆绑器版本1.14.6
红宝石2.4.0p0
感谢您的帮助
编辑
我正在尝试在本地环境中执行此操作,我想在heroku上执行此操作没有问题。
EDIT
I'm trying to do this in my local environment, I guess there would be no problem doing this on heroku.
推荐答案
从您的评论中我了解到,您希望heroku配置可在本地开发中使用。
From your comments I understand that you expect the heroku config to be available in local development. This is not the case as you recognized.
您需要要求您在Gemfile中提到的 heroku_env.rb
。 Gemfile只是在特定上下文中执行的普通Ruby文件。因此,您应该只需要在顶部添加 require‘config / heroku_env’
-或您的路径是什么即可。请记住在结尾处省略 .rb
。
You need to require that heroku_env.rb
you mentioned in your Gemfile. The Gemfile is just a plain Ruby file executed in a specific context. So, you should be able to just add require 'config/heroku_env'
to the top - or whatever your path is. Remember to omit the .rb
at the end.
,请尝试使用 heroku local
: https: //devcenter.heroku.com/articles/heroku-local
这篇关于Gemfile中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!