【问题标题】:How to resolve Rail 6 deploy error on AWS Elastic Beanstalk for ruby 2.7.1如何为 ruby​​ 2.7.1 解决 AWS Elastic Beanstalk 上的 Rail 6 部署错误
【发布时间】:2020-09-22 09:56:32
【问题描述】:

我正在尝试通过 Elastic Beanstalk 在 AWS 上部署 Rails 6 应用程序。

当我运行eb deploy 时,它失败了。 当我查看日志时,我看到了这条消息

2020/06/03 14:19:51.457403 [ERROR] rbenv: version `2.7.0' is not installed (set by /var/app/staging/.ruby-version)

2020/06/03 14:19:51.457439 [ERROR] An error occurred during execution of command [app-deploy] - [stage ruby application]. Stop running the command. Error: install dependencies in Gemfile failed with error Command /bin/sh -c bundle config set --local deployment true failed with error exit status 1. Stderr:rbenv: version `2.7.0' is not installed (set by /var/app/staging/.ruby-version)

但是,当我 eb ssh 并运行 ruby -v 时,我看到我正在运行 ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]

所以我将Gemfile.ruby-version 更新为ruby 2.7.1 以匹配我的AWS 环境。

当我cd /var/app/stagingcat .ruby-version 我得到2.7.1

那么为什么这次部署失败了?我在项目中的任何地方都不需要ruby 2.7.0

我已经确定git push,所以我知道我的 Gemfile 被推送到我的回购。 尝试部署这个 Rails 应用程序我快疯了。

【问题讨论】:

  • 尝试将部署策略更改为不可变(在“滚动更新和部署”配置下)。这将每次将您的代码部署在新的服务器上,排除旧文件被读取的可能性。
  • @David 我现在也遇到了同样的问题,请问你是怎么解决的?
  • @littleforest 您的解决方案无法解决问题
  • @chrisgeeq - 我已经在这上面花了 160 多个小时,但我仍然没有弄清楚。我没有放弃,但我只是暂时休息一下。
  • @DavidLee 也有同样的问题,虽然我的问题通过重建环境解决了,你试过了吗?还要确保您的 gemfile 和 ruby​​-version 引用了正确的版本。

标签: ruby-on-rails amazon-web-services amazon-elastic-beanstalk web-deployment ruby-on-rails-6


【解决方案1】:

在你的目录的根目录中有一个 .ruby-version 文件,它声明了一个不同的 ruby​​ 版本,就像在你的情况下它会是 ruby​​-2.7.0,只需将其更改为 ruby​​-2.7.1 或其他任何内容你的 Gemfile。

【讨论】:

    【解决方案2】:

    我认为您可以设置 ruby​​ 并根据您的要求将其设为默认值。 只需在 .ebextensions 中设置一些配置文件并设置说明以安装您需要的 ruby​​ 版本并将其设为默认值。 例如

    1. 在 .ebextensions 00_ruby_install.config 中创建文件
    2. 添加将安装 ruby​​ 的内容
    files:
      "/opt/elasticbeanstalk/hooks/appdeploy/pre/09_ruby_install.sh" :
        mode: "000775"
        owner: root
        group: users
        content: |
          #!/usr/bin/env bash
          ... Add ruby install instructions here ...
    

    【讨论】:

      【解决方案3】:

      对我有用的是在您的应用程序的根目录中创建一个 zip 文件:

      zip ../rails-default.zip -r * .[^.]
      

      https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ruby-rails-tutorial.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-04-09
        • 2019-02-22
        • 2021-08-28
        • 2017-10-04
        • 2020-06-05
        • 2014-12-16
        • 2018-12-03
        • 2020-04-25
        相关资源
        最近更新 更多