如何解决将Rails应用程序部署到Heroku的麻烦? [英] How can I solve this trouble to deploy a Rails App to Heroku?

查看:75
本文介绍了如何解决将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'

但是我更改了红宝石版本以适合heroku 18.

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

我安装了rvm install"ruby​​-2.5.3"

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

我确实运行了捆绑安装程序(无错误消息)

最后,我确实运行了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

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

谢谢!

解决方案

我发布的解决方案可能会迟到,但可以帮助其他人. 大多数人发布的解决方案要求升级红宝石版本.在应用程序中更新红宝石版本可能会花费一些时间. 但是使用以下解决方案,应用程序可以部署而无需更新ruby版本.

heroku当前使用的堆栈是heroku-18,具有Ubuntu 18.04的映像.它具有最低支持的运行时为ruby 2.4.5此处的其他信息. /p>

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

打开控制台并运行heroku stack,您将找到.

  cedar-14
  container
  heroku-16
* heroku-18

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

heroku stack:set heroku-16

现在,如果您运行heroku stack,您将找到针对您的应用程序的heroku-16堆栈集.

  cedar-14
  container
* heroku-16
  heroku-18

您可能会在控制台上找到安全漏洞问题,此处的信息.

尝试仅将链轮上的宝石更新到最低3.7.2,例如:

bundle update sprockets --bundler '3.7.2'

或者您可以设置:

config.assets.compile = false # Disables security vulnerability

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

I'm having trouble to deploy a rails app to Heroku.

When I tried to push my project to Heroku (git push heroku master), it gave me this error :

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'

However I changed my ruby version to fit with heroku 18.

I searched here https://devcenter.heroku.com/articles/ruby-support#supported-runtimes for a ruby version that is currently compatible

I installed rvm install "ruby-2.5.3"

I added the line ruby '2.5.3' to the App's Gemfile

I did run bundle install (No Error Messages)

And finally, I did run git push heroku master

Here my 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

I saw this similar question: Having Trouble to deploy a Rails App to Heroku but the answer advised to go to the same link as above...

Thanks!

解决方案

I am posting solution might be late but can help other. Solution most people posting asking to upgrade ruby version. Updating ruby version in an application might be time consuming some time. But with below solution application can deploy without updating ruby version.

Current stack heroku uses is heroku-18, Having image of Ubuntu 18.04. It have minimum supported runtime is ruby 2.4.5, other information here.

To run aplication with below this ruby version you need to downgrade heroku stack for your application.

Open console and run heroku stack you will find.

  cedar-14
  container
  heroku-16
* heroku-18

You need to downgrade to stack which support your ruby version. For ruby 2.3.x you can set heroku-16

heroku stack:set heroku-16

Now if you run heroku stack you will find heroku-16 stack set for your application.

  cedar-14
  container
* heroku-16
  heroku-18

You might get security vulnerability issue on console, Information here.

Try update only sprockets gem to minimum 3.7.2 like:

bundle update sprockets --bundler '3.7.2'

Or you can set :

config.assets.compile = false # Disables security vulnerability

Run git push heroku master. Boom!! Your application deployed successfully.

这篇关于如何解决将Rails应用程序部署到Heroku的麻烦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆