I am writing a sinatra app, which runs successfully on localhost, but when I try to push it on heroku, and open the root path, the app crashes.
When the app is pushed to heroku, and I open the logs, I get:
Gem::Exception: can't find executable rackup for gem rack
Full log:
2021-01-06T11:40:37.313507+00:00 app[scheduler.6910]: bundler: failed to load command: rake (/app/vendor/bundle/ruby/2.7.0/bin/rake)
2021-01-06T11:40:37.313575+00:00 app[scheduler.6910]: Gem::Exception: can't find executable rake for gem rake. rake is not currently included in the bundle, perhaps you meant to add it to your Gemfile?
2021-01-06T11:40:37.313577+00:00 app[scheduler.6910]: /app/vendor/bundle/ruby/2.7.0/gems/bundler-2.1.4/lib/bundler/rubygems_integration.rb:374:in `block in replace_bin_path'
2021-01-06T11:40:37.313577+00:00 app[scheduler.6910]: /app/vendor/bundle/ruby/2.7.0/gems/bundler-2.1.4/lib/bundler/rubygems_integration.rb:402:in `block in replace_bin_path'
2021-01-06T11:40:37.313578+00:00 app[scheduler.6910]: /app/vendor/bundle/ruby/2.7.0/bin/rake:23:in `<top (required)>'
2021-01-06T11:41:25.609385+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/badge.svg" host=linuxstatloc.herokuapp.com request_id=96c4fe30-253a-46b1-9f95-ff2515c980ab fwd="140.82.115.249" dyno= connect= service= status=503 bytes= protocol=https
My Gemfile:
source 'https://rubygems.org'
gem 'rack'
gem 'rake'
gem 'sinatra'
gem 'linux_stat'
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
linux_stat (1.3.0)
mustermann (1.1.1)
ruby2_keywords (~> 0.0.1)
rack (2.2.3)
rack-protection (2.1.0)
rack
rake (13.0.3)
ruby2_keywords (0.0.2)
sinatra (2.1.0)
mustermann (~> 1.0)
rack (~> 2.2)
rack-protection (= 2.1.0)
tilt (~> 2.0)
tilt (2.0.10)
PLATFORMS
x86_64-linux
DEPENDENCIES
bundler
linux_stat
rack
rake
sinatra
BUNDLED WITH
2.2.3
Procfile:
dev: bundle exec rackup -o 0 -p 8080
web: APP_ENV=production bundle exec rackup -p "$PORT"
config.ru
require './app'
run Sinatra::Application
app:
require 'sinatra'
require 'linux_stat'
require 'json'
require 'zlib'
require './methods/badger'
require './methods/update'
before {
headers['Content-Encoding'] = 'deflate'.freeze
}
get '/' do
content_type 'image/svg+xml'.freeze
Update.data
Zlib.deflate(Badger.generate_svg, 9)
end
get '/badge.svg' do
content_type 'image/svg+xml'.freeze
Update.data
Zlib.deflate(Badger.generate_svg, 9)
end
get '/json' do
Update.data
content_type :json
Zlib.deflate(Badger.get_json.to_json, 9)
end
get '/stats' do
content_type :json
Zlib.deflate(Badger::stats.to_json, 9)
end
not_found do
content_type 'text/html'
html = <<~EOF.lines.each(&:strip!).join(?
.freeze)
<!Doctype HTML><html>
<head><meta charset="utf-8"><title>404</title></head><body>
#{request.url} is not a valid URL!<br><br>Valid URLs are:<br>
<a href="#{request.base_url}/">/</a><br>
<a href="#{request.base_url}/badge.svg">/badge.svg</a><br>
<a href="#{request.base_url}/stats">/stats</a><br>
<a href="#{request.base_url}/json">/json</a><br></body></html>
EOF
Zlib.deflate(html, 9)
end
I am not getting why I can't run rack. If I open heroku's BASH, I can't run rack. If I install it with gem there, I can't still run rack. I have also tried running gem update
and bundle update
on heroku bash, but it's still not working.
But in the heroku bash, I can run irb, and load all the gems normally. So they are installed, but can't execute them.
Any idea why the app is crashing constantly?
Edit:
It's weird. On my local system I created a directory called ./vendor/. Then I ran cp `which rackup` ./vendor/
which copied rackup from my system to a newly created /vendor/ directory. I have also modified the Procfile:
dev: bundle exec rackup -o 0 -p 8080
web: APP_ENV=production ./vendor/rackup -p "$PORT"
And I pushed the changes to heroku. It's working now. I suspect this is version issue.
Although the Gemfile.lock has all the necessary versions, I can't really get anything from rake to rack to work. I am clueless what to do. Because the solution now I have now is a temporary solution that could break in the future.