Rails aws elastic beanstalk 数据库适配器部署错误

Rails aws elastic beanstalk deploy error with database adapter

我正在尝试根据本文的指导将我的 rails 应用程序部署到 aws elastic beanstalk。

https://medium.com/@jatescher/how-to-set-up-a-rails-4-2-app-on-aws-with-elastic-beanstalk-and-postgresql-3f9f29c046e2#.tnssj8z0o

在开始之前,"Using PostgreSQL with Rails" 部分,我没有遇到任何问题。

在那部分,我按照gem文件修改,将postgreSQL gem添加到生产组,并将sqlite3 gem移动到开发和测试组,如我做了其他 rails 个应用程序。

像这样

group :development, :test do
   # Before insert this group, sqlite3 gem code is in the default group. (Outside of development group)
   gem 'sqlite3', '~> 1.3.10' 
   ...other gems...
end
group :production do
   gem 'pg', '~> 0.18.1'
end

之后,我$ bundle install$ git commit$ eb deploy。但是这一次,EBS 报错了下面的信息

ERROR: [Instance: i-80ee5327] Command failed on instance. Return code: 1 Output: (TRUNCATED)...sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Gem::LoadError: sqlite3 is not part of the bundle. Add it to Gemfile.

Tasks: TOP => db:migrate => db:load_config (See full trace by running task with --trace).

Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].

ERROR: Unsuccessful command execution on instance id(s) 'i-80ee5327'. Aborting the operation.

ERROR: Failed to deploy application.

通过阅读错误消息,我发现 sqlite3 gem 没有被 aws 实例加载,所以我将 sqlite3 gem 代码发布到开发组之外。

gem 'sqlite3', '~> 1.3.10' 

group :development, :test do
   ...other gems...
end
group :production do
   gem 'pg', '~> 0.18.1'
end

在那之后,$ eb deploy命令运行良好,服务器正常运行。

所以,我的问题是...为什么会出现这个问题?

在我看来,如果我像第二个版本那样制作 gem 文件,默认环境会加载 sqlite3 适配器,并且应该在生产环境中崩溃。但是结果和我完全相反。这是非常烦人的情况,更重要的是,我怀疑我是否在做正确的解决方案。

请帮帮我...

这是我当前的环境变量。

 RACK_ENV = development 
 SECRET_KEY_BASE = **********
 RAILS_SKIP_MIGRATIONS = false 
 RAILS_SKIP_ASSET_COMPILATION = false
 BUNDLE_WITHOUT = test:development

看来您 运行 您的 beantalk 服务器处于开发模式。确保在 beantalk 中设置了以下环境变量:

RAILS_ENV=production
RACK_ENV=production