ruby-on-rails - 数据库适配器的 Rails aws elastic beanstalk 部署错误

标签 ruby-on-rails postgresql sqlite rubygems amazon-elastic-beanstalk

我正尝试按照本文的指导将我的 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

在开始“将 PostgreSQL 与 Rails 结合使用”部分之前,我没有遇到任何问题。

在那部分,我遵循了 gemfile 修改,将 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 命令运行良好,服务器正常运行。

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

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

请帮帮我...

这是我当前的环境变量。

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

最佳答案

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

RAILS_ENV=production
RACK_ENV=production

关于ruby-on-rails - 数据库适配器的 Rails aws elastic beanstalk 部署错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34995647/

相关文章:

c++ - 如果同时运行,BIGSERIAL 事务是否安全? (PostgreSQL,libpqxx)

java - 如何将 SQLite 数据从 Android 发送到 MySQL 服务器?

Android SQLite 原始查询参数

ruby-on-rails - Rails WHERE 查询 has_many 关系不正确?

php - SQLite 在通过 URL 访问时显示数据

ruby-on-rails - 在调用 Rake 任务时设置多个环境变量

ruby-on-rails - 用什么代替 respond_with

ruby-on-rails - Rails 应用程序错误页面上的 Google Analytics 跟踪代码

用于 Snow Leopard 安装的 Mysql gem

sql - PostgreSQL 中的批量/批量更新/更新插入