此错误信息是众所周知的错误信息。 (例如,请参阅https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html。)尽管我是通过带有Ruby 2.6.1和bundler 2.0.1的新Elastic Beanstalk应用程序获得它的。错误是:

  /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)

我尝试将以下文件:01_install_bundler.config放入.ebextensions文件夹中:
container_commands:
  01_install_bundler:
    command: "gem install bundler —-version 2.0.1"

尽管此操作永远不会执行,因为如果我看上面的错误,我可以看到它在部署过程的这一点上正在发生:
.../AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.

(即在AppDeployPreHook脚本的bundle install命令期间)。请参阅https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html以获取PlatformHooks的引用。

我非常确定,如果可以确保使用的捆绑器版本至少为2.0.0,那么不会有问题。虽然我不知道如何轻松指定。目前,我正在向服务器发送/opt/elasticbeanstalk/hooks/appdeploy/pre/进行编辑和处理脚本。尽管我显然需要一种自动的,可重复的方法。

令人沮丧的是,ruby 2.6.1默认情况下未选择捆绑程序版本2.0.0。有任何想法吗?

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

更新:

如果我编辑文件/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

并添加gem install bundler(不带加号),则此问题得以解决,因为它安装了最新的捆绑程序,即2.0.1。对于那些想知道黑客的人,命令是:
eb sshsudo -icd /opt/elasticbeanstalk/hooks/appdeploy/previm 10_bundle_install.sh
该解决方案的问题在于,由于它不使用.ebextensions,因此感觉有点像骇客。有解决此问题的更合适的方法吗?

最佳答案

因此,这是上述问题的程序化解决方案。在.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

然后,当您下一个eb deploy时,捆绑器将被更新到版本2.0.1,您将不会再收到上述错误。

文档中的更多信息在这里:

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

和这里:

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

最后注意事项:确保在运行eb deploy之前提交这些更改,或者暂存它们并运行eb deploy --staged。请参阅:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html。我经过惨痛的教训才学到这个!

10-05 20:29