在 Elastic Beanstalk 上部署时出错 - Rails

Posted

技术标签:

【中文标题】在 Elastic Beanstalk 上部署时出错 - Rails【英文标题】:Error Deploying on Elastic Beanstalk - Rails 【发布时间】:2019-05-25 01:21:15 【问题描述】:

我正在尝试在 Elastic Beanstalk 上部署自定义项目,但是当 puma 启动时,我的 puma.log 文件中出现以下错误。我不知道如何解决这个问题。我认为它可能与我的 yaml 解析器有关,但我不完全确定如何使用 EB 更新它。任何帮助将不胜感激。

=== puma startup: 2018-12-26 22:06:02 +0000 ===
/opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/psych.rb:402:in 'parse': (<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 83 column 22 (Psych::SyntaxError)
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/psych.rb:402:in 'parse_stream'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/psych.rb:350:in 'parse'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/psych.rb:263:in 'load'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/secrets.rb:27:in 'block in parse'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/secrets.rb:24:in 'each'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/secrets.rb:24:in 'each_with_object'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/secrets.rb:24:in 'parse'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/application.rb:391:in 'secrets'
from /var/app/current/config/environments/production.rb:96:in 'block in <top (required)>'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/railtie.rb:211:in 'instance_eval'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/railtie.rb:211:in 'configure'
from /var/app/current/config/environments/production.rb:1:in '<top (required)>'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in 'require'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in 'block in require'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:258:in 'load_dependency'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/activesupport-5.1.6.1/lib/active_support/dependencies.rb:292:in 'require'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/engine.rb:600:in 'block (2 levels) in <class:Engine>'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/engine.rb:599:in 'each'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/engine.rb:599:in 'block in <class:Engine>'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/initializable.rb:30:in 'instance_exec'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/initializable.rb:30:in 'run'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/initializable.rb:59:in 'block in run_initializers'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:228:in 'block in tsort_each'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:350:in 'block (2 levels) in each_strongly_connected_component'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:422:in 'block (2 levels) in each_strongly_connected_component_from'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:431:in 'each_strongly_connected_component_from'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:421:in 'block in each_strongly_connected_component_from'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/initializable.rb:48:in 'each'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/initializable.rb:48:in 'tsort_each_child'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:415:in 'call'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:415:in 'each_strongly_connected_component_from'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:349:in 'block in each_strongly_connected_component'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:347:in 'each'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:347:in 'call'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:347:in 'each_strongly_connected_component'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:226:in 'tsort_each'
from /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/tsort.rb:205:in 'tsort_each'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/initializable.rb:58:in 'run_initializers'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/railties-5.1.6.1/lib/rails/application.rb:353:in 'initialize!'
from /var/app/current/config/environment.rb:5:in '<top (required)>'
from config.ru:3:in 'require_relative'
from config.ru:3:in 'block in <main>'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:55:in 'instance_eval'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:55:in 'initialize'
from config.ru:in 'new'
from config.ru:in '<main>'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:49:in 'eval'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:49:in 'new_from_string'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/rack-2.0.6/lib/rack/builder.rb:40:in 'parse_file'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/configuration.rb:318:in 'load_rackup'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/configuration.rb:243:in 'app'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/runner.rb:155:in 'app'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/runner.rb:162:in 'start_server'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:273:in 'worker'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:137:in 'block (2 levels) in spawn_workers'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:137:in 'fork'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:137:in 'block in spawn_workers'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:133:in 'times'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:133:in 'spawn_workers'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cluster.rb:466:in 'run'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/launcher.rb:184:in 'run'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/cli.rb:78:in 'run'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/puma-3.12.0/bin/puma:10:in '<top (required)>'
from /opt/rubies/ruby-2.5.3/bin/puma:23:in 'load'
from /opt/rubies/ruby-2.5.3/bin/puma:23:in '<top (required)>'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in 'load'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:74:in 'kernel_load'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli/exec.rb:28:in 'run'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:424:in 'exec'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/command.rb:27:in 'run'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/invocation.rb:126:in 'invoke_command'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor.rb:387:in 'dispatch'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:27:in 'dispatch'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/vendor/thor/lib/thor/base.rb:466:in 'start'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/cli.rb:18:in 'start'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/exe/bundle:30:in 'block in <top (required)>'
from /opt/rubies/ruby-2.5.3/lib/ruby/site_ruby/2.5.0/bundler/friendly_errors.rb:124:in 'with_friendly_errors'
from /opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0/gems/bundler-1.16.2/exe/bundle:22:in '<top (required)>'
from /opt/rubies/ruby-2.5.3/bin/bundle:23:in 'load'
from /opt/rubies/ruby-2.5.3/bin/bundle:23:in '<main>'

我今天再次查看了日志以确保我没有遗漏任何内容,并且我确实在不同的日志文件中看到了对相同错误的另一个引用,但它仍然告诉我很少。

-------------------------------------
/var/log/eb-commandprocessor.log
-------------------------------------
++ [[ -z /opt/rubies/ruby-2.5.3 ]]
++ shift
++ chruby_use /opt/rubies/ruby-2.5.3 ''
++ [[ ! -x /opt/rubies/ruby-2.5.3/bin/ruby ]]
++ [[ -n '' ]]
++ export RUBY_ROOT=/opt/rubies/ruby-2.5.3
++ RUBY_ROOT=/opt/rubies/ruby-2.5.3
++ export RUBYOPT=
++ RUBYOPT=
++ export PATH=/opt/rubies/ruby-2.5.3/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
++ PATH=/opt/rubies/ruby-2.5.3/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
+++ /opt/rubies/ruby-2.5.3/bin/ruby -
++ eval 'export RUBY_ENGINE=ruby;
export RUBY_VERSION=2.5.3;
export GEM_ROOT="/opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0";'
+++ export RUBY_ENGINE=ruby
+++ RUBY_ENGINE=ruby
+++ export RUBY_VERSION=2.5.3
+++ RUBY_VERSION=2.5.3
+++ export GEM_ROOT=/opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0
+++ GEM_ROOT=/opt/rubies/ruby-2.5.3/lib/ruby/gems/2.5.0
++ ((  0 != 0  ))
+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb assets:precompile' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
+ '[' false == true ']'
+ su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler/home/webapp' as your home directory temporarily.
rake aborted!
Psych::SyntaxError: (<unknown>): did not find expected alphabetic or numeric character while scanning an alias at line 83 column 22
/var/app/ondeck/config/environments/production.rb:96:in `block in <top (required)>'
/var/app/ondeck/config/environments/production.rb:1:in `<top (required)>'
/var/app/ondeck/config/environment.rb:5:in `<top (required)>'
/opt/rubies/ruby-2.5.3/bin/bundle:23:in `load'
/opt/rubies/ruby-2.5.3/bin/bundle:23:in `<main>'
Tasks: TOP => environment
(See full trace by running task with --trace) (Executor::NonZeroExitStatus)

【问题讨论】:

您在部署过程中得到的究竟是什么日志?另外,你可以去 eb 仪表板和日志获取最后 100 行日志吗? @7urkm3n 这就是 puma.log 文件中的确切错误。仪表板仅显示我的整体实例运行状况的状态为 Warning,而我的单实例状态的状态为 Degraded。尝试从浏览器访问站点时出现 504 Gateway Timeout 错误。 不,您必须转到 EB 仪表板/日志并获取最后一个日志。它应该与我记得的不同。我不知道psych.rbline 83 是什么。确保在 localhost 1st 中运行生产应用程序。 是的,这就是这个错误来自“EB 仪表板/日志并获取最后一个日志”的地方。顺便说一句,我在 Heroku 服务器上运行了这个应用程序,但出于定价目的,我正在迁移到 AWS。 @7urkm3n 请使用code block 而不是内联代码正确格式化您的堆栈跟踪。 【参考方案1】:

如果app/shared/assets 下有任何 .json 清单文件,请尝试删除它们。

此错误也可能由于 YAML 文件错误而产生。您可以通过运行这个小脚本(在 Rails 根目录中)来检查这一点,该脚本在所有子目录中递归查找所有 *.yml 文件并测试该文件。

require 'yaml'

d = Dir["./**/*.yml"]
d.each do |file|
  begin
    puts "checking : #file"
    f =  YAML.load_file(file)
  rescue StandardError
    puts "failed to read #file: #$!"
  end
end

【讨论】:

以上是关于在 Elastic Beanstalk 上部署时出错 - Rails的主要内容,如果未能解决你的问题,请参考以下文章

在 Elastic Beanstalk 上运行 npm install 时出现问题

将 asp.net core web api 部署到 aws elastic beanstalk 时出现错误 404

将 PHP 应用程序部署到 Elastic Beanstalk 时出现问题

部署到 Elastic Beanstalk 时出现 JavaAgentDetector 错误

在 AWS Elastic Beanstalk 上部署 Geodjango 应用程序

AWS Elastic Beanstalk 使用 CLI 部署时出现 Botocore 错误