简体   繁体   English

Elastic Beanstalk:找不到带有可执行包的 gem bundler (>= 0.a) (Gem::GemNotFoundException)

[英]Elastic Beanstalk: can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

This error message is a well known error message.此错误消息是众所周知的错误消息。 (see https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html for example.) Although I'm getting it with a new Elastic Beanstalk application with Ruby 2.6.1, and bundler 2.0.1. (例如,请参阅https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html 。)虽然我使用新的 Elastic Beanstalk 应用程序获取它Ruby 2.6.1 和捆绑器 2.0.1。 The error is:错误是:

  /opt/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0/rubygems.rb:289:in `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
from /opt/rubies/ruby-2.6.1/lib/ruby/site_ruby/2.6.0/rubygems.rb:308:in `activate_bin_path'
from /opt/rubies/ruby-2.6.1/bin/bundle:23:in `<main>' (ElasticBeanstalk::ExternalInvocationError)

I've tried putting the following file: 01_install_bundler.config in the .ebextensions folder:我尝试将以下文件: 01_install_bundler.config放在.ebextensions文件夹中:

container_commands:
  01_install_bundler:
    command: "gem install bundler —-version 2.0.1"

Although this never gets run because if I look at the above error, I can see that it is happening during this point in the deploy process:虽然这永远不会运行,因为如果我查看上面的错误,我可以看到它发生在部署过程的这一点上:

.../AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.

(ie during the bundle install command of an AppDeployPreHook script). (即在 AppDeployPreHook 脚本的bundle install命令期间)。 See https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html for reference of PlatformHooks.有关 PlatformHooks 的参考,请参阅https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html

I'm pretty sure that if I can ensure that the version of bundler being used is at least version 2.0.0, then there won't be a problem.我很确定,如果我能确保所使用的 bundler 版本至少是 2.0.0 版本,那么就不会有问题。 Although I don't know how I can specify that easily.虽然我不知道如何轻松指定。 At the moment I'm ssh'ing to the server to /opt/elasticbeanstalk/hooks/appdeploy/pre/ to edit and fiddle with the scripts.目前我正在通过 ssh 连接到服务器到/opt/elasticbeanstalk/hooks/appdeploy/pre/来编辑和摆弄脚本。 Although I obviously need an automated, repeatable way of doing it.虽然我显然需要一种自动化的、可重复的方式来做这件事。

It's frustrating that ruby 2.6.1 isn't choosing bundler version 2.0.0 by default.令人沮丧的是,ruby 2.6.1 默认没有选择捆绑程序版本 2.0.0。 Any ideas?有任何想法吗?

============================== ==============================

Update:更新:

If I edit the file /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh如果我编辑文件/opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh

if [ -f Gemfile ]; then
  echo "running 'bundle install' with Gemfile:"
  cat Gemfile

  +++ gem install bundler +++
  if [ -d $EB_APP_STAGING_DIR/vendor/cache ]; then
    bundle install --local
  else
    bundle install
  fi
else
  echo "no Gemfile found! Skipping bundle install stage!"
fi

and add the gem install bundler (without the pluses), then this fixes the problem because it installs the latest bundler, which is 2.0.1.并添加gem install bundler (没有加号),然后这解决了问题,因为它安装了最新的 bundler,即 2.0.1。 For those who want to know the hack, the commands were:对于那些想知道 hack 的人,命令是:

eb ssh

sudo -i

cd /opt/elasticbeanstalk/hooks/appdeploy/pre

vim 10_bundle_install.sh

The problem with this solution is that it feels like a bit of a hack because it doesn't use .ebextensions .这个解决方案的问题在于它感觉有点像黑客,因为它不使用.ebextensions Is there a more proper way of fixing this?有没有更合适的方法来解决这个问题?

So here's the programmatic solution to the above problem.所以这里是上述问题的程序化解决方案。 Create the below file under .ebextensions/gem_install_bundler.config :.ebextensions/gem_install_bundler.config下创建以下文件:

files:
  # Runs before `./10_bundle_install.sh`:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/09_gem_install_bundler.sh" :
    mode: "000775"
    owner: root
    group: users
    content: |
      #!/usr/bin/env bash

      EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k app_staging_dir)
      EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
      # Source the application's ruby, i.e. 2.6. Otherwise it will be 2.3, which will give this error: `bundler requires Ruby version >= 2.3.0` 
      . $EB_SCRIPT_DIR/use-app-ruby.sh

      cd $EB_APP_STAGING_DIR
      echo "Installing compatible bundler"
      gem install bundler -v 2.0.1

Then when you next eb deploy , the bundler will have been updated to version 2.0.1, and you won't get the above error again.然后当你下次eb deploy ,bundler 就会更新到 2.0.1 版本,你就不会再出现上面的错误了。

More information in the docs here:此处文档中的更多信息:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html

and here:和这里:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-files https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-files

Last note: Ensure that you either commit these changes before running eb deploy , or stage them and run eb deploy --staged .最后一点:确保您要么在运行eb deploy之前提交这些更改,要么eb deploy --staged它们并运行eb deploy --staged See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html .请参阅: https : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html I learned this the hard way!我经过惨痛的教训才学到这个!

我只是在找到替代(也许更简单)解决方案后才看到这篇文章:将 bundler 回溯到 1.17.3( gem unistall bundler之后是gem install bundler -v 1.17.3

Here is a version that can be used on the new Amazon Linux 2 platform versions as the old /opt/elasticbeanstalk/hooks/ folders are entirely discontinued.这是一个可用于新 Amazon Linux 2 平台版本的版本,因为旧的/opt/elasticbeanstalk/hooks/文件夹已完全停止使用。 It parses the bundler version out of the Gemfile.lock它从 Gemfile.lock 中解析出打包器版本

This script would go into .platform/hooks/prebuild/01_install_app_bundler.sh and it needs to be marked as executable or it will fail with a permissions issue ( chmod +x 01_install_app_bundler.sh )此脚本将进入.platform/hooks/prebuild/01_install_app_bundler.sh并且需要将其标记为可执行文件,否则会因权限问题而失败( chmod +x 01_install_app_bundler.sh

#!/usr/bin/env bash

# Load environment data
EB_APP_STAGING_DIR=$(/opt/elasticbeanstalk/bin/get-config platformconfig -k AppStagingDir)
EB_APP_USER=$(/opt/elasticbeanstalk/bin/get-config platformconfig -k AppUser)
EB_APP_DEPLOY_DIR=$(/opt/elasticbeanstalk/bin/get-config platformconfig -k AppDeployDir)

# Set up correct environment
export $(cat /opt/elasticbeanstalk/deployment/env | xargs)

BUNLDER_VER_TO_INSTALL=$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n1 | tr -d ' ')

echo "Installing bundler $BUNLDER_VER_TO_INSTALL"
gem install bundler -v $BUNLDER_VER_TO_INSTALL

I left some unused EB_ variables in there just to show how they can be determined on the updated platform.我在那里留下了一些未使用的 EB_ 变量,只是为了展示如何在更新的平台上确定它们。

You need the correct version of the bundler that the lockfile was generated with.您需要生成锁定文件的捆绑程序的正确版本。 To find out that version, use the following command要找出该版本,请使用以下命令

$ cat Gemfile.lock | grep -A 1 "BUNDLED WITH"
BUNDLED WITH
   1.17.3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 捆绑器:在使用 gem 进行捆绑安装期间找不到带有可执行捆绑包 (Gem::GemNotFoundException) 的 gem bundler (&gt;= 0.a) - Bundler: can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException) during bundle install with gem TRAVIS CI:`find_spec_for_exe':找不到带有可执行包的 gem bundler (&gt;= 0.a) (Gem::GemNotFoundException) - TRAVIS CI: `find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException) 找不到带有可执行轨道的 gem railties (&gt;= 0.a) (Gem::GemNotFoundException) - Can't find gem railties (>= 0.a) with executable rails (Gem::GemNotFoundException) 找不到带有可执行 jekyll (Gem::GemNotFoundException) 的 gem jekyll (>= 0.a) - can't find gem jekyll (>= 0.a) with executable jekyll (Gem::GemNotFoundException) 找不到带有可执行 rdebug-ide (Gem::GemNotFoundException) 的 gem ruby​​-debug-ide (&gt;= 0.a) - can't find gem ruby-debug-ide (>= 0.a) with executable rdebug-ide (Gem::GemNotFoundException) 找不到宝石铁路(&gt; = 0.a)(Gem :: GemNotFoundException) - can't find gem railties (>= 0.a) (Gem::GemNotFoundException) 在heroku上找不到gem bundler(&gt; = 0)(Gem :: GemNotFoundException) - can't find gem bundler (>= 0) (Gem::GemNotFoundException) on heroku 找不到宝石导轨 - Gem::GemNotFoundException - can't find gem rails - Gem::GemNotFoundException Rails 找不到宝石 Railties (&gt;=0.a) - Rails Can't Find Gem Railties (>=0.a) Elastic Beanstalk,Bundler找不到gem“bundler”的兼容版本 - Elastic Beanstalk, Bundler could not find compatible versions for gem “bundler”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM