【问题标题】:How can I solve this trouble to deploy a Rails App to Heroku?如何解决将 Rails 应用程序部署到 Heroku 的问题?
【发布时间】:2019-04-20 14:54:32
【问题描述】:

我无法将 rails 应用程序部署到 Heroku。

当我尝试将我的项目推送到 Heroku(git push heroku master)时,它给了我这个错误:

Counting objects: 300, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (269/269), done.
Writing objects: 100% (300/300), 255.34 KiB | 6.08 MiB/s, done.
Total 300 (delta 73), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote:  !     Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used.
remote:             Detected buildpacks: Ruby,Node.js
remote:             See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote:        Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.5.tgz -s -o - | tar zxf - ' failed on attempt 1 of 3.
remote:        Command: 'set -o pipefail; curl -L --fail --retry 5 --retry-delay 1 --connect-timeout 3 --max-time 30 https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-18/ruby-2.3.5.tgz -s -o - | tar zxf - ' failed on attempt 2 of 3.
remote: 
remote:  !
remote:  !     An error occurred while installing ruby-2.3.5
remote:  !     
remote:  !     This version of Ruby is not available on Heroku-18. The minimum supported version
remote:  !     of Ruby on the Heroku-18 stack can found at:
remote:  !     
remote:  !     https://devcenter.heroku.com/articles/ruby-support#supported-runtimes
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected to agora-challenge.
remote: 
To https://git.heroku.com/agora-challenge.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/agora-challenge.git'

但是我更改了我的 ruby​​ 版本以适应 heroku 18。

我在这里搜索https://devcenter.heroku.com/articles/ruby-support#supported-runtimes 寻找当前兼容的 ruby​​ 版本

我安装了 rvm install "ruby-2.5.3"

我将 ruby​​ '2.5.3' 行添加到应用程序的 Gemfile 中

我确实运行了捆绑安装(没有错误消息)

最后,我确实运行了 git push heroku master

这是我的 Gemfile

source 'https://rubygems.org'
ruby '2.5.3'


gem 'jbuilder', '~> 2.0'
gem 'pg', '~> 0.21'
gem 'puma'
gem 'rails', '5.1.6'
gem 'redis'

gem 'autoprefixer-rails'
gem 'bootstrap-sass', '~> 3.3'
gem 'font-awesome-sass', '~> 5.0.9'
gem 'sass-rails'
gem 'simple_form'
gem 'uglifier'
gem 'webpacker'
gem 'devise'

group :development do
  gem 'web-console', '>= 3.3.0'
end

group :development, :test do
  gem 'pry-byebug'
  gem 'pry-rails'
  gem 'listen', '~> 3.0.5'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'dotenv-rails'
end

我看到了这个类似的问题:Having Trouble to deploy a Rails App to Heroku 但建议转到与上面相同的链接...

谢谢!

【问题讨论】:

  • 看来您使用的 Ruby 版本不是您 Gemfile 中的版本。检查:stackoverflow.com/questions/1589751/… 还要检查:stackoverflow.com/questions/7777235/…
  • 你解决了吗?以防万一,发布解决方案,也许有一天我会需要它......
  • 哦,是的,对不起。但我不明白我是如何解决这个问题的。我输入 rvm install ruby​​-2.5.3。之后,当我输入 irb RUBY_VERSION 时,注意到了好版本“2.5.3”。所以我试图推动(git push heroku master)。同样的错误:An error occurred while installing ruby-2.3.5 remote: ! remote: ! This version of Ruby is not available on Heroku-18 所以我清理了我的分支(git add . > git commit > git push origin master > git remote -v)。最后,我再次尝试:git push heroku master。这是工作!
  • 你可以降级heroku堆栈来解决这个问题。可以在这里找到解决方案stackoverflow.com/questions/53354444/…

标签: ruby-on-rails ruby heroku


【解决方案1】:

您应该有一个.ruby-version 文件,其中包含2.5.3

【讨论】:

    【解决方案2】:

    我发布的解决方案可能会迟到,但可以帮助其他人。 大多数人发布要求升级 ruby​​ 版本的解决方案。在应用程序中更新 ruby​​ 版本可能会耗费一些时间。 但是使用以下解决方案应用程序可以在不更新 ruby​​ 版本的情况下进行部署。

    heroku 使用的当前堆栈是 heroku-18,具有 Ubuntu 18.04 的映像。它支持的最低运行时为ruby 2.4.5、other information here。

    要运行低于此 ruby​​ 版本的应用程序,您需要为您的应用程序降级 heroku 堆栈。

    打开控制台运行heroku stack你会发现。

      cedar-14
      container
      heroku-16
    * heroku-18
    

    您需要降级到支持您的 ruby​​ 版本的堆栈。对于ruby 2.3.x,您可以设置heroku-16

    heroku stack:set heroku-16
    

    现在,如果您运行 heroku stack,您将找到为您的应用程序设置的 heroku-16 堆栈。

      cedar-14
      container
    * heroku-16
      heroku-18
    

    您可能会在控制台上遇到安全漏洞问题,Information here。

    尝试仅将 sprockets gem 更新到最低 3.7.2 喜欢:

    bundle update sprockets --bundler '3.7.2'
    

    或者你可以设置:

    config.assets.compile = false # Disables security vulnerability
    

    运行git push heroku master。繁荣!!您的应用部署成功。

    【讨论】:

      【解决方案3】:

      请在此处查看每个堆栈(cedar 14、cedar 16 和 cedar 18)中安装的 Ubuntu 软件包。

      https://devcenter.heroku.com/articles/stack-packages#installed-ubuntu-packages

      在列表中搜索“ruby”并为应用程序选择适当的 cedar 堆栈。

      我希望这些信息可以帮助其他人。

      【讨论】:

        猜你喜欢
        • 2011-10-03
        • 1970-01-01
        • 2016-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-25
        • 2018-03-31
        • 2016-01-06
        相关资源
        最近更新 更多