gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 06:58:07 27 4
gpt4 key购买 nike

此错误消息是众所周知的错误消息。 (例如,参见 https://bundler.io/blog/2019/01/04/an-update-on-the-bundler-2-release.html。)虽然我是通过一个新的 Elastic Beanstalk 应用程序获得它的,该应用程序具有 Ruby 2.6.1 和 bundler 2.0.1。错误是:

  /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 引用。

我很确定,如果我能确保使用的 bundler 版本至少是 2.0.0 版本,那么就不会有问题。虽然我不知道如何轻松指定。目前,我正在通过 SSH 连接到服务器以 /opt/elasticbeanstalk/hooks/appdeploy/pre/ 编辑和摆弄脚本。尽管我显然需要一种自动化的、可重复的方式来完成它。

令人沮丧的是,ruby 2.6.1 没有默认选择 bundler 版本 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(没有加号),这就解决了问题,因为它安装了最新的 bundler ,即 2.0.1。对于那些想了解黑客的人,命令是:

eb ssh

sudo -i

cd/opt/elasticbeanstalk/hooks/appdeploy/pre

vim 10_bundle_install.sh

这个解决方案的问题在于它感觉有点像 hack,因为它不使用 .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时,bundler已经更新到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 .我通过艰难的方式学到了这一点!

关于ruby-on-rails - Elastic Beanstalk:找不到带有可执行包的 gem bundler (>= 0.a) (Gem::GemNotFoundException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55360450/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com