安装 gems 部署失败 - AWS Elastic Beanstalk

Posted

技术标签:

【中文标题】安装 gems 部署失败 - AWS Elastic Beanstalk【英文标题】:Installing gems fails in deployment - AWS Elastic Beanstalk 【发布时间】:2017-01-24 07:22:46 【问题描述】:

当我尝试在 AWS Elastic Beanstalk(EB) 环境中部署应用程序时,未安装本机 gem。

eb-activity.log

  Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
  installing your bundle as root will break this application for all non-root
  users on this machine.
  Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
  fatal: Not a git repository (or any of the parent directories): .git
  fatal: Not a git repository (or any of the parent directories): .git
  Fetching gem metadata from https://rubygems.org/
  Fetching version metadata from https://rubygems.org/
  Fetching dependency metadata from https://rubygems.org/
  Resolving dependencies...
  Installing rake 11.2.2
  Installing i18n 0.7.0
  Using json 1.8.3
  Installing minitest 5.9.0
  Installing thread_safe 0.3.5
  Installing builder 3.2.2
  Installing erubis 2.7.0
  Installing mini_portile2 2.1.0
  Installing pkg-config 1.1.7
  Installing rack 1.6.4
  Installing mime-types-data 3.2016.0521
  Installing arel 6.0.3
  Installing jmespath 1.3.1
  Installing bcrypt 3.1.11 with native extensions

  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

      current directory: /var/app/ondeck/gems/bundle/gems/bcrypt-3.1.11/ext/mri
  /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-19gpiil.rb extconf.rb
  Cannot allocate memory - /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-19gpiil.rb extconf.rb 2>&1

  Gem files will remain installed in /var/app/ondeck/gems/bundle/gems/bcrypt-3.1.11 for inspection.
  Results logged to /var/app/ondeck/gems/bundle/extensions/x86_64-linux/2.3.0-static/bcrypt-3.1.11/gem_make.out
  Using bundler 1.12.1
  Installing rubyzip 1.2.0
  Installing coderay 1.1.1
  Installing coffee-script-source 1.10.0
  Installing execjs 2.7.0
  Installing thor 0.18.1
  Installing concurrent-ruby 1.0.2
  Installing orm_adapter 0.5.0
  Installing unf_ext 0.0.7.2 with native extensions

  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

      current directory: /var/app/ondeck/gems/bundle/gems/unf_ext-0.0.7.2/ext/unf_ext
  /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-1kl25wy.rb extconf.rb
  Cannot allocate memory - /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-1kl25wy.rb extconf.rb 2>&1

  Gem files will remain installed in /var/app/ondeck/gems/bundle/gems/unf_ext-0.0.7.2 for inspection.
  Results logged to /var/app/ondeck/gems/bundle/extensions/x86_64-linux/2.3.0-static/unf_ext-0.0.7.2/gem_make.out
  Installing hashie 3.4.4
  Installing htmlentities 4.3.4
  Installing multi_xml 0.5.5
  Installing multi_json 1.12.1
  Installing jwt 1.5.4
  Installing method_source 0.8.2
  Installing mimemagic 0.3.0
  Installing mqtt 0.4.0
  Installing netrc 0.11.0
  Installing pg 0.18.4 with native extensions

  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

      current directory: /var/app/ondeck/gems/bundle/gems/pg-0.18.4/ext
  /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-4s0qe7.rb extconf.rb
  Cannot allocate memory - /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-4s0qe7.rb extconf.rb 2>&1

  Gem files will remain installed in /var/app/ondeck/gems/bundle/gems/pg-0.18.4 for inspection.
  Results logged to /var/app/ondeck/gems/bundle/extensions/x86_64-linux/2.3.0-static/pg-0.18.4/gem_make.out
  Installing slop 3.6.0
  Installing rack-cors 0.4.0
  Installing sass 3.4.22
  Installing tilt 2.0.5
  Installing turbolinks-source 5.0.0
  Installing will_paginate 3.1.0
  Installing apipie-rails 0.3.6
  Installing rdoc 4.2.2
  Installing tzinfo 1.2.2
  Installing nokogiri 1.6.8 with native extensions

  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

      current directory: /var/app/ondeck/gems/bundle/gems/nokogiri-1.6.8/ext/nokogiri
  /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-13djrm9.rb extconf.rb
  Cannot allocate memory - /opt/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20160916-26394-13djrm9.rb extconf.rb 2>&1

  Gem files will remain installed in /var/app/ondeck/gems/bundle/gems/nokogiri-1.6.8 for inspection.
  Results logged to /var/app/ondeck/gems/bundle/extensions/x86_64-linux/2.3.0-static/nokogiri-1.6.8/gem_make.out
  Installing rack-test 0.6.3
  Installing warden 1.2.6
  Installing mime-types 3.1
  Installing aws-sdk-core 2.6.1
  An error occurred while installing bcrypt (3.1.11), and Bundler cannot continue.
  Make sure that `gem install bcrypt -v '3.1.11'` succeeds before bundling. (Executor::NonZeroExitStatus)

我尝试了以下方法:

    在 EB /var/app/current 目录中使用 gem update bundler 命令更新捆绑程序,但没有改进。 在本地删除 gemfile.lockbundle install 并部署更新 gemfile.lock

上面的错误每次都会出现。

我正在使用带有 ruby​​ 2.3 版本的 Rails 4.2.4

请帮助我。谢谢。

【问题讨论】:

【参考方案1】:

我终于通过缓存 gem 解决了这个问题。

我在本地运行 bundle package,它会在 vendor/cache 目录中创建 gem 缓存。

现在,在 AWS 中部署这些缓存的 gem 时,它会尝试使用缓存的 gem,而不是安装它。我不知道这是否是一个好习惯,但它解决了我的问题。

我从 AWS 博客中获得了这个解决方案:Locally Packaging Gem Dependencies for Ruby Applications in Elastic Beanstalk

编辑#1:在答案中添加@sybind 的评论

bundle package --all 将包括all :git references

如果有更好的解决方案,请告诉我。

【讨论】:

捆绑包 --all 将包括所有 :git 引用 我在打包时收到Some gems seem to be missing from your vendor/cache directory. Could not find nokogiri-1.12.4 in any of the sources。我可以在供应商/缓存中看到nokogiri-1.12.4-x86_64-darwin

以上是关于安装 gems 部署失败 - AWS Elastic Beanstalk的主要内容,如果未能解决你的问题,请参考以下文章

从 git 引用 ruby​​ gem 会破坏 aws beanstalk 部署

在 AWS 弹性 beantalk 上使用 webpacker gem 部署 rails react 应用程序

使用 AWS OpsWorks 设计 gem 初始化

如何在 AWS Elastic Beanstalk 上安装/运行 Spark Java 框架?

将 React 应用程序部署到 AWS

Rails 部署到 AWS ElasticBeanstalk/RDS 失败