是否有任何理由不在Heroku上使用RAILS_ENV = staging? [英] Are there any reasons not to use RAILS_ENV=staging on Heroku?
问题描述
位于
The Heroku documentation at https://devcenter.heroku.com/articles/deploying-to-a-custom-rails-environment says I shouldn't use a staging.rb file to define my staging environment.
创建另一个自定义环境(例如"staging")并创建config/environments/staging.rb并使用RAILS_ENV = staging部署到Heroku应用程序可能很诱人.
It may be tempting to create another custom environment such as "staging" and create a config/environments/staging.rb and deploy to a Heroku app with RAILS_ENV=staging.
这不是一个好习惯.相反,我们建议始终在生产模式下运行,并通过设置config vars来修改任何行为.
This is not a good practice. Instead we recommend always running in production mode and modifying any behavior by setting your config vars.
我认为这是一个糟糕的建议,并且与公认的Rails最佳实践相冲突.但是,我不是在这里讨论最佳实践.我在这里问:
I think this is terrible advice and conflicts with well-established Rails best practice. However, I'm not here to argue about best practices. I'm here to ask:
是否有任何理由不在Heroku上使用RAILS_ENV = staging?
Are there any reasons not to use RAILS_ENV=staging on Heroku?
如果我创建一个staging.rb文件并像这样设置xxx_ENV配置变量,是否有任何东西会损坏?
Is there anything that will break if I create a staging.rb file and set the xxx_ENV config vars like this?
heroku config:add RACK_ENV=staging --remote staging
heroku config:add RAILS_ENV=staging --remote staging
推荐答案
不,如果执行此操作,不会破坏任何内容.
No, there isn't anything that will break if you do this.
但是,我确实认为Heroku就在这里(请注意,我在Heroku工作).
当阶段环境和生产环境之间唯一改变的地方应该是配置变量时,它介绍了阶段环境和生产环境之间可能存在的差异.
Heroku已经提供了使用config:set
命令设置配置变量的安全方法.
使用2个配置文件意味着您必须维护相同的配置两次,并且可能会出现问题,因为您在阶段中正确地更新了配置,但是在生产中错误地更新了该配置.
However, I do think that Heroku is right here (note that I work at Heroku).
It introduces possible differences between your staging and production environments, when the only thing that changes between them should be configuration variables.
Heroku already provides a secure mean of setting configuration variables, with the config:set
command.
Using 2 config files means you have to maintain the same configuration twice, and possible can have issues because you updated the configuration correctly in staging, but incorrectly in production.
请注意,RACK_ENV
只能有3个值:production
,development
和none
.参见 https://www.hezmatt.org/~mpalmer/blog/2013/10/13/rack_env-its-not-for-you.html
As a side note, RACK_ENV
should only ever have 3 values: production
, development
and none
. See https://www.hezmatt.org/~mpalmer/blog/2013/10/13/rack_env-its-not-for-you.html
这篇关于是否有任何理由不在Heroku上使用RAILS_ENV = staging?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!