我正在尝试使用弹性beanstalk启动rails applciation的暂存实例。我按照文档进行了以下操作:
eb init --environment staging
eb start --environment staging
在此之后,我检查了.elasticbeanstalk / optionsettings仍然以'production'作为环境。我手动将其更新为暂存,并尝试了git aws.push命令。
一段时间后,所有内容都已部署,但是,当我加载URL时,应用程序似乎仍在使用所有生产配置而不是暂存。我错过了任何一步吗?
答案 0 :(得分:8)
--environment
CLI工具中的eb
开关未引用Rails环境,它指的是您尝试启动的Elastic Beanstalk环境。 Elastic Beanstalk环境是已部署的应用程序版本的一组配置资源。这与Rails / Rack环境不同,后者只是用户定义的上下文,用于在单个机器上运行应用程序代码。
为了设置 Rails环境,您需要在RACK_ENV
文件中设置RAILS_ENV
(或.elasticbeanstalk/optionsettings
)环境变量。 eb start
然后调用eb update
来触发这些环境变量的更新。或者,您可以通过Elastic Beanstalk console编辑 Elastic Beanstalk环境配置;单击正确环境中的“环境详细信息”,在“概述”中单击“编辑配置”,然后转到“容器”以调整环境变量(在这种情况下,您将编辑RACK_ENV
字段)。
答案 1 :(得分:1)
虽然我使用eb_deployer而非eb
命令行,但在尝试部署RAILS_ENV: development
时,我发现db:migrate
等在开发环境中运行,但它仍然以生产模式启动服务器。要解决这个问题,需要在option_settings中传入RACK_ENV和RAILS_ENV:
[{
namespace: 'aws:elasticbeanstalk:application:environment',
option_name: 'RACK_ENV',
value: "development"
},
{
namespace: 'aws:elasticbeanstalk:application:environment',
option_name: 'RAILS_ENV',
value: "development"
}]
答案 2 :(得分:1)
以下是第一次将应用程序部署到elasticbeanstalk的明确指南。
1)eb init --profile profile-name(配置文件名称将在.aws> config中)
2)根据需要选择默认区域,输入序列号。
3)输入序列号,选择要使用的应用程序。
4)eb list
5)eb使用(列表中的名称)
6)eb状态(会给你状态) 这就是你完成了初始化。 现在,如果你想改变环境,只需使用以下命令。
eb setenv RACK_ENV =分期(需要一段时间)。
eb deploy(在git staging之后)。
你完成了!!!!