如何解决将 Rails 应用程序部署到 Heroku 的问题?

cle*_*cle 2 ruby ruby-on-rails heroku

我无法将 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'
Run Code Online (Sandbox Code Playgroud)

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

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

我安装了 rvm install "ruby-2.5.3"

我在应用程序的 Gemfile 中添加了 ruby​​ '2.5.3' 行

我确实运行了 bundle install (没有错误消息)

最后,我确实运行了 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
Run Code Online (Sandbox Code Playgroud)

我看到了这个类似的问题:将 Rails 应用程序部署到 Heroku 时遇到问题但答案建议转到与上面相同的链接...

谢谢!

Dip*_*pta 7

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

heroku 当前使用的堆栈是 heroku-18,具有 Ubuntu 18.04 的映像。它有最低支持的运行时间ruby 2.4.5其他信息在这里

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

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

  cedar-14
  container
  heroku-16
* heroku-18
Run Code Online (Sandbox Code Playgroud)

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

heroku stack:set heroku-16
Run Code Online (Sandbox Code Playgroud)

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

  cedar-14
  container
* heroku-16
  heroku-18
Run Code Online (Sandbox Code Playgroud)

您可能会在控制台上遇到安全漏洞问题,信息在这里

尝试仅将 sprockets gem 更新为最小值,3.7.2例如:

bundle update sprockets --bundler '3.7.2'
Run Code Online (Sandbox Code Playgroud)

或者你可以设置:

config.assets.compile = false # Disables security vulnerability
Run Code Online (Sandbox Code Playgroud)

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