Elastic Beanstalk:找不到具有可执行包(Gem :: GemNotFoundException)的gem bundler(> = 0.a) [英] Elastic Beanstalk: can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)

查看:114
本文介绍了Elastic Beanstalk:找不到具有可执行包(Gem :: GemNotFoundException)的gem bundler(> = 0.a)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我尝试将以下文件:01_install_bundler.config放在.ebextensions文件夹中:

I've tried putting the following file: 01_install_bundler.config in the .ebextensions folder:

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.

(即在AppDeployPreHook脚本的bundle install命令期间).参见 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html 供PlatformHooks参考.

(i.e. during the bundle install command of an AppDeployPreHook script). See https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html for reference of PlatformHooks.

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

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. 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. Although I obviously need an automated, repeatable way of doing it.

令人沮丧的是,Ruby 2.6.1在默认情况下未选择捆绑程序版本2.0.0.有什么想法吗?

It's frustrating that ruby 2.6.1 isn't choosing bundler version 2.0.0 by default. Any ideas?

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

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

更新:

如果我编辑文件/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.对于那些想了解黑客的人,命令是:

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. For those who want to know the hack, the commands were:

eb ssh

sudo -i

cd /opt/elasticbeanstalk/hooks/appdeploy/pre

vim 10_bundle_install.sh

此解决方案的问题在于,由于它不使用.ebextensions,因此感觉有点像骇客.有更合适的解决方法吗?

The problem with this solution is that it feels like a bit of a hack because it doesn't use .ebextensions. Is there a more proper way of fixing this?

推荐答案

因此,这是上述问题的程序化解决方案.在.ebextensions/gem_install_bundler.config下创建以下文件:

So here's the programmatic solution to the above problem. Create the below file under .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,您将不会再收到上述错误.

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.

此处的文档中有更多信息:

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/customize-containers-ec2.html#linux-files

最后的注意:确保您在运行eb deploy之前提交了这些更改,或者暂存并运行eb deploy --staged.请参阅: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html .我是很难学到的!

Last note: Ensure that you either commit these changes before running eb deploy, or stage them and run eb deploy --staged. See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cli-git.html. I learned this the hard way!

这篇关于Elastic Beanstalk:找不到具有可执行包(Gem :: GemNotFoundException)的gem bundler(&gt; = 0.a)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆