stw*_*667 8 ruby rubygems ruby-on-rails amazon-web-services amazon-elastic-beanstalk
此错误信息是众所周知的错误信息。(例如,请参阅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)
Run Code Online (Sandbox Code Playgroud)
我尝试将以下文件:01_install_bundler.config
放在.ebextensions
文件夹中:
container_commands:
01_install_bundler:
command: "gem install bundler —-version 2.0.1"
Run Code Online (Sandbox Code Playgroud)
尽管这永远不会运行,因为如果我看上面的错误,我可以看到它在部署过程的这一点上正在发生:
.../AppDeployStage0/AppDeployPreHook/10_bundle_install.sh] : Activity failed.
Run Code Online (Sandbox Code Playgroud)
(即在bundle install
AppDeployPreHook脚本的命令期间)。请参阅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
Run Code Online (Sandbox Code Playgroud)
并添加gem install bundler
(不包括加号),则此问题得以解决,因为它安装了最新的捆绑程序,即2.0.1。对于那些想知道黑客的人,命令是:
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
. Is there a more proper way of fixing this?
stw*_*667 15
因此,这是上述问题的程序化解决方案。在下面创建以下文件.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
Run Code Online (Sandbox Code Playgroud)
然后,当您下一步时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。我经过惨痛的教训才学到这个!