Rails aws弹性beanstalk与数据库适配器的部署错误

时间:2022-08-25 08:40:07

I'm trying to deploy my rails application to aws elastic beanstalk, with guidance of this article.

在本文的指导下,我正在尝试将rails应用程序部署到aws弹性beanstalk上。

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

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

Before starting, "Using PostgreSQL with Rails" part, I had no problems.

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

In that part, I followed the gemfile modifying, which adds the postgreSQL gem to the production group, and moves sqlite3 gem to the development & test group, as I did other rails apps.

在这一部分中,我跟踪了gemfile修改,它将postgreSQL gem添加到生产组,并将sqlite3 gem移动到开发和测试组,就像我做其他rails应用一样。

Like this

像这样

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

After then, I $ bundle install, $ git commit, and $ eb deploy. But in this time, EBS makes error with below messages

之后,我将$ bundle install、$ git commit和$ eb部署。但是在这段时间,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).

错误:[Instance: i-80ee5327]命令实例失败。返回码:1输出:(截断)…sqlite3' ' ' '到Gemfile(并确保其版本是ActiveRecord所要求的最小版本)。

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

LoadError: sqlite3不是bundle的一部分。将它添加到Gemfile。

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

任务:TOP => db:migrate => db:load_config(通过运行task with—trace来查看完整的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.

钩/ opt / elasticbeanstalk / / appdeploy / pre / 12 _db_migration Hook。sh失败了。要了解更多细节,请检查/var/log/eb-activity。使用控制台或EB CLI进行日志记录。

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

信息:命令执行在所有实例上完成。总结:[成功:0,失败:1]。

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

错误:在实例id上执行命令失败“我- 80 ee5327”。流产手术。

ERROR: Failed to deploy application.

错误:部署应用程序失败。

By reading error messages, I catch that the sqlite3 gem is not loadded by aws instance, so I put out the sqlite3 gem code to outside of development group.

通过读取错误消息,我发现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

After that, the $ eb deploy command works well and server works.

之后,$ eb部署命令可以正常工作,服务器也可以正常工作。

So, my question is... WHY this problem happens?

所以,我的问题是……为什么会发生这个问题?

In my thought, if I make gemfile like 2nd version, sqlite3 adapter is loaded by default environment and should be crashing in production environment. But the result is completely opposite to me. This is very annoying situation and, to be more, I'm in doubt whether I'm doing the right solution.

在我的想法中,如果我让gemfile像第二个版本,sqlite3适配器是由默认环境加载的,并且应该在生产环境中崩溃。但结果和我完全相反。这是非常恼人的情况,而且,我怀疑我是否在做正确的解决方案。

Please help me...

请帮我…

This is my current environment variables.

这是我当前的环境变量。

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

1 个解决方案

#1


4  

it appears you're running your beanstalk server in development mode. make sure you have the following env variables set in beanstalk:

在开发模式下,您将运行beanstalk服务器。确保在beanstalk中设置了以下env变量:

RAILS_ENV=production
RACK_ENV=production

#1


4  

it appears you're running your beanstalk server in development mode. make sure you have the following env variables set in beanstalk:

在开发模式下,您将运行beanstalk服务器。确保在beanstalk中设置了以下env变量:

RAILS_ENV=production
RACK_ENV=production