创建新的 Elastic Beanstalk 工作程序环境时 RubyVersionMismatch
Posted
技术标签:
【中文标题】创建新的 Elastic Beanstalk 工作程序环境时 RubyVersionMismatch【英文标题】:RubyVersionMismatch when creating new Elastic Beanstalk worker environment 【发布时间】:2016-06-18 13:33:21 【问题描述】:第一次来电,长期倾听。我有一个在 AWS Elastic Beanstalk Web 服务器环境中运行没有问题的 Rails 应用程序,我现在想将一个类似的应用程序部署到工作环境,以对上传的文件进行一些异步处理。现在,为了让它继续运行,我将我的应用程序的相同版本(换句话说,一个在多个 Web 服务器环境中运行良好的版本)部署到工作环境(它使用与 Web 服务器环境相同的平台) ,但在尝试执行初始 rake assets:precompile
时得到 RubyVersionMismatch:
$ tail -n 100 /var/log/eb-activity.log
+ RAKE_TASK=assets:precompile
+ . /opt/elasticbeanstalk/support/scripts/use-app-ruby.sh
++ . /usr/local/share/chruby/chruby.sh
+++ CHRUBY_VERSION=0.3.8
+++ RUBIES=()
+++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
+++ [[ -d /opt/rubies ]]
++++ ls -A /opt/rubies
+++ [[ -n ruby-1.9.3-p551
ruby-2.0.0-p598
ruby-2.1.5
ruby-2.2.2
ruby-current ]]
+++ RUBIES+=("$dir"/*)
+++ for dir in '"$PREFIX/opt/rubies"' '"$HOME/.rubies"'
+++ [[ -d /.rubies ]]
+++ unset dir
+++ cat /etc/elasticbeanstalk/.ruby_version
++ chruby 2.2.2
++ case "$1" in
++ local dir match
++ for dir in '"$RUBIES[@]"'
++ dir=/opt/rubies/ruby-1.9.3-p551
++ [[ ruby-1.9.3-p551 == *\2\.\2\.\2* ]]
++ for dir in '"$RUBIES[@]"'
++ dir=/opt/rubies/ruby-2.0.0-p598
++ [[ ruby-2.0.0-p598 == *\2\.\2\.\2* ]]
++ for dir in '"$RUBIES[@]"'
++ dir=/opt/rubies/ruby-2.1.5
++ [[ ruby-2.1.5 == *\2\.\2\.\2* ]]
++ for dir in '"$RUBIES[@]"'
++ dir=/opt/rubies/ruby-2.2.2
++ [[ ruby-2.2.2 == *\2\.\2\.\2* ]]
++ match=/opt/rubies/ruby-2.2.2
++ for dir in '"$RUBIES[@]"'
++ dir=/opt/rubies/ruby-current
++ [[ ruby-current == *\2\.\2\.\2* ]]
++ [[ -z /opt/rubies/ruby-2.2.2 ]]
++ shift
++ chruby_use /opt/rubies/ruby-2.2.2 ''
++ [[ ! -x /opt/rubies/ruby-2.2.2/bin/ruby ]]
++ [[ -n '' ]]
++ export RUBY_ROOT=/opt/rubies/ruby-2.2.2
++ RUBY_ROOT=/opt/rubies/ruby-2.2.2
++ export RUBYOPT=
++ RUBYOPT=
++ export PATH=/opt/rubies/ruby-2.2.2/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
++ PATH=/opt/rubies/ruby-2.2.2/bin:/opt/elasticbeanstalk/lib/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
+++ /opt/rubies/ruby-2.2.2/bin/ruby -
++ eval 'export RUBY_ENGINE=ruby;
export RUBY_VERSION=2.2.2;
export GEM_ROOT="/opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0";'
+++ export RUBY_ENGINE=ruby
+++ RUBY_ENGINE=ruby
+++ export RUBY_VERSION=2.2.2
+++ RUBY_VERSION=2.2.2
+++ export GEM_ROOT=/opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0
+++ GEM_ROOT=/opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.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
+ '[' false == true ']'
+ su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
/opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.6/lib/bundler/definition.rb:379:in `validate_ruby!': Your Ruby version is 2.1.5, but your Gemfile specified 2.2.2 (Bundler::RubyVersionMismatch)
from /opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.6/lib/bundler.rb:118:in `setup'
from /opt/rubies/ruby-2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.6/lib/bundler/setup.rb:18:in `<top (required)>'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require' (Executor::NonZeroExitStatus)
[2016-03-04T15:28:08.146Z] INFO [1693] - [CMD-Startup/StartupStage0/AppDeployPreHook/11_asset_compilation.sh] : Activity failed.
[2016-03-04T15:28:08.147Z] INFO [1693] - [CMD-Startup/StartupStage0/AppDeployPreHook] : Activity failed.
[2016-03-04T15:28:08.147Z] INFO [1693] - [CMD-Startup/StartupStage0] : Activity failed.
[2016-03-04T15:28:08.147Z] INFO [1693] - [CMD-Startup] : Completed activity. Result:
Command CMD-Startup failed.
我的 Gemfile 实际上确实调用了 v2.2.2,但是如果您注意到,堆栈跟踪的底部两行显示正在调用的 ruby 位于 /opt/elasticbeanstalk 中,尽管事实上 chruby 正确地找到了并从 /opt/rubies/ruby-current 中选择 2.2.2 版本。任何想法为什么会发生这种情况?如果 EB 要随机回退到自己的本地版本,那么根据 containerconfig 动态选择 ruby 版本有什么意义?
【问题讨论】:
您是否尝试在 Rails 项目的根目录中添加.ruby-version
文件?它只需要包含您选择用于该特定 Rails 项目的 Ruby 版本。
我确实有一个,设置为 2.2.2,但认为这只对 rvm 和 rbenv 有帮助,而 EB 使用 chruby
很奇怪。您是否运行任何自定义配置文件或特殊 ami?
库存 AMI。我有一个 .ebextensions 文件来安装特定版本的 rake 和 rack(gem install -i /opt/rubies/ruby-current/lib/ruby/gems/2.2.0 rack -v 1.6.4
、gem install -i /opt/rubies/ruby-current/lib/ruby/gems/2.2.0 rake -v 10.5.0
),但我认为这不会影响它。
你觉得这个怎么样?我目前遇到了同样的问题。
【参考方案1】:
我不确定您是否对移动平台持开放态度,但您是否考虑过使用 docker? (https://www.docker.com)
【讨论】:
我们已经考虑过了,将来可能会这样做,但现在真的没有时间去做。以上是关于创建新的 Elastic Beanstalk 工作程序环境时 RubyVersionMismatch的主要内容,如果未能解决你的问题,请参考以下文章
AWS Elastic Beanstalk CRON 作业设置
Elastic Beanstalk:环境创建持续时间与不可变部署