我的bundler命令无法加载到部署在Heroku中的Sinatra应用程序中,因此导致它崩溃 [英] My bundler command is failing to load in my Sinatra app deployed in Heroku and thus causes it to crash
本文介绍了我的bundler命令无法加载到部署在Heroku中的Sinatra应用程序中,因此导致它崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将一个非常初级的Sinatra应用程序成功部署到Heroku。我可以在本地运行此应用程序。Ruby代码本身非常简单:
require 'sinatra'
get '/' do
'Hello World!'
end
我添加了正确的Gemfile:
source 'https://rubygems.org'
gem 'sinatra'
gem 'rack'
以及配置文件:
require './hello_app'
run SinatraApp
此代码在Heroku上成功构建:
-----> Ruby app detected
-----> Installing bundler 2.1.4
-----> Removing BUNDLED WITH version in the Gemfile.lock
-----> Compiling Ruby/Rack
-----> Using Ruby version: ruby-2.6.6
-----> Installing dependencies using bundler 2.1.4
Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
Using bundler 2.1.4
Using ruby2_keywords 0.0.2
Using mustermann 1.1.1
Using rack 2.2.3
Using rack-protection 2.1.0
Using tilt 2.0.10
Using sinatra 2.1.0
Bundle complete! 2 Gemfile dependencies, 7 gems now installed.
Gems in the groups development and test were not installed.
Bundled gems are installed into `./vendor/bundle`
Bundle completed (0.49s)
Cleaning up the bundler cache.
-----> Detecting rake tasks
###### WARNING:
You have not declared a Ruby version in your Gemfile.
To declare a Ruby version add this line to your Gemfile:
```
ruby "2.6.6"
```
For more information see:
https://devcenter.heroku.com/articles/ruby-versions
###### WARNING:
No Procfile detected, using the default web server.
We recommend explicitly declaring how to boot your server process via a Procfile.
https://devcenter.heroku.com/articles/ruby-default-web-server
-----> Discovering process types
Procfile declares types -> (none)
Default types for buildpack -> console, rake, web
-----> Compressing...
Done: 13.5M
-----> Launching...
Released v6
https://arcane-depths-40341.herokuapp.com/ deployed to Heroku
但是,当我部署它并实际访问站点时,它崩溃了,日志中显示以下内容:
2020-12-22T14:04:23.100758+00:00 heroku[web.1]: State changed from crashed to starting
2020-12-22T14:04:24.857234+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p ${PORT:-5000}`
2020-12-22T14:04:28.910617+00:00 app[web.1]: bundler: failed to load command: rackup (/app/vendor/bundle/ruby/2.6.0/bin/rackup)
2020-12-22T14:04:28.910647+00:00 app[web.1]: Gem::Exception: can't find executable rackup for gem rack. rack is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
2020-12-22T14:04:28.910648+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.1.4/lib/bundler/rubygems_integration.rb:374:in `block in replace_bin_path'
2020-12-22T14:04:28.910648+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/bundler-2.1.4/lib/bundler/rubygems_integration.rb:402:in `block in replace_bin_path'
2020-12-22T14:04:28.910648+00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/bin/rackup:23:in `<top (required)>'
2020-12-22T14:04:29.001978+00:00 heroku[web.1]: Process exited with status 1
2020-12-22T14:04:29.106041+00:00 heroku[web.1]: State changed from starting to crashed
2020-12-22T18:56:39.441582+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=arcane-depths-40341.herokuapp.com request_id=875e2357-d1f9-4457-ab68-3d6a76bea281 fwd="98.13.129.57" dyno= connect= service= status=503 bytes= protocol=https
我的两个问题是:
- 为什么会发生这种情况?
- 如何修复以使应用程序成功加载到Heroku?
推荐答案
标识的问题
您有许多问题,但最大的问题是您正在尝试run SinatraApp
而不是run Sinatra::Application
。这很可能是导致应用程序崩溃的原因,Heroku和Sinatra文档中都有正确的调用。
此外,Sinatra README建议使用瘦Web服务器。Herokurecommends using a Procfile,它显式定义了大多数基于Ruby的应用程序的Web服务器调用。具体地说,它写着:
下面,我为Sinatra应用程序提供了我自己的建议配置,与Heroku文档中提供的配置相比(稍微)不那么简约。从那里开始,然后根据需要进行调整。无论您选择哪种Web服务器,生产应用程序都应始终在Procfile中显式指定Web服务器。
使用Foreman配置文件在Heroku上启动Sinatra
首先,确保您的应用程序的Heroku堆栈包括heroku/ruby
构建包。然后,使用foremanProcfile通过瘦Web服务器启动Sinatra应用程序。例如:
# Gemfile
ruby '2.6.6'
source 'https://rubygems.org'
gem 'sinatra'
gem 'thin'
gem 'foreman'
# config.ru
require './hello_app'
run Sinatra::Application
# Procfile
dev: bundle exec rackup
web: APP_ENV=production bundle exec rackup -p "$PORT"
您可能可以让它与其他配置一起工作,包括minimalist one suggested by Heroku,但是这个设置可以在Heroku上的大量Sinatra应用程序上可靠地工作。您使用其他配置的里程(和错误数)可能会有所不同。
这篇关于我的bundler命令无法加载到部署在Heroku中的Sinatra应用程序中,因此导致它崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文