Deploying a static Rack site to Heroku fails with 'bundler: command not found: rackup' in Heroku logs

43 views Asked by At

I have followed the following Heroku post to create and deploy a static Rack based website: https://devcenter.heroku.com/articles/static-sites-ruby

Here's my configuration:

Gemfile:

# frozen_string_literal: true

source "https://rubygems.org"

gem "rack"

config.ru:

use Rack::Static,
  :urls => [
    "/assets/scss/base", 
    "/assets/scss/themes",
    ...
],
  :root => "public"

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public/index.html', File::RDONLY)
  ]
}

Procfile:

web: bundle exec rackup config.ru -p $PORT

I can deploy to Heroku fine. But, when I try to open the app, I get the following errors:

2023-11-07T16:37:21.427599+00:00 heroku[web.1]: State changed from crashed to starting
2023-11-07T16:37:22.915905+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p 54175`
2023-11-07T16:37:23.722932+00:00 heroku[web.1]: Process exited with status 127
2023-11-07T16:37:23.632062+00:00 app[web.1]: bundler: command not found: rackup
2023-11-07T16:37:23.632097+00:00 app[web.1]: Install missing gem executables with `bundle install`
2023-11-07T16:37:23.749287+00:00 heroku[web.1]: State changed from starting to crashed

Initially I didn't have a Procfile because that isn't described in the article. It sounded like Heroku would just assume the Dyno configuration I needed. However, after deploying to Heroku, I could see in the Heroku console that it wanted me to add the Procfile.

I re-ran bundle install just to make sure. But, that yielded no changes to any files.

Is there an additional gem that is needed? Does my Procfile config need to change? Or, is it something else?

1

There are 1 answers

0
Brad Eaton On

Added 'ruby "3.1.3"' and "rackup" to my Gemfile and reran bundle install.

Gemfile:

# frozen_string_literal: true

source "https://rubygems.org"

ruby "3.1.4"

gem "rack"
gem "rackup"

This allowed rackup to run. However a new error popped up that this question solved:

uninitialized constant Rack::Static (NameError) using rackup

config.ru:

require 'rack/static'

use Rack::Static,
  :urls => [
    "/assets/scss/base", 
    "/assets/scss/themes", 
    ...
],
  :root => "public"

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public/index.html', File::RDONLY)
  ]
}

So it seems that one of these 2 things solved the original issue:

  1. Declaring the ruby version in the Gemfile and running bindle install again
  2. Adding the rackup gem to the project directly.