我正尝试按照本文的指导将我的 Rails 应用程序部署到 aws elastic beanstalk。
在开始“将 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/