[英]How can I solve this trouble to deploy a Rails App to 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'
但是我更改了我的 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
我看到了這個類似的問題: 將 Rails 應用程序部署到 Heroku 時遇到問題,但答案建議轉到與上面相同的鏈接...
謝謝!
我發布的解決方案可能會遲到但可以幫助其他人。 大多數人發帖要求升級 ruby 版本的解決方案。 在應用程序中更新 ruby 版本可能會耗費一些時間。 但是使用以下解決方案,應用程序可以在不更新 ruby 版本的情況下進行部署。
heroku 當前使用的堆棧是 heroku-18,具有 Ubuntu 18.04 的映像。 它支持的最低運行時是ruby 2.4.5
, 其他信息在這里。
要在此 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
您可能會在控制台上遇到安全漏洞問題,信息在這里。
嘗試僅將 sprockets gem 更新到最低3.7.2
例如:
bundle update sprockets --bundler '3.7.2'
或者你可以設置:
config.assets.compile = false # Disables security vulnerability
運行git push heroku master
。 繁榮!! 您的應用程序部署成功。
您應該有一個.ruby-version
文件,其中包含2.5.3
請在此處檢查安裝在每個堆棧(cedar 14、cedar 16 和 cedar 18)中的 Ubuntu 軟件包。
https://devcenter.heroku.com/articles/stack-packages#installed-ubuntu-packages
在列表中搜索“ruby”並為應用程序選擇合適的雪松堆棧。
我希望這些信息可以幫助其他人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.