Deploying Sinatra App (With Config.Ru) on Heroku Cedar Stack

Deploying sinatra app (with config.ru) on heroku cedar stack

I had to update my Procfile because the RACK_ENV isn't passed into the heroku environment. The Procfile became:

web: bundle exec thin -R config.ru start -p $PORT -e $RACK_ENV

How can I deploy a Sinatra-based Ruby web app to Heroku?

When deploying from a different branch into Heroku's master branch, you need to specify the branch in the push command: git push heroku heroku:master.

Do I need a Procfile to push a Sinatra app to Heroku?

Heroku knows how to launch different types of applications by default and it tries to detect your type of app when you deploy. If you have a config.ru for example, Heroku knows you’re deploying a rack app and then rack uses that file.

A custom Procfile is needed if you want to customize the command that boots up your application, for example to run it with a different webserver or to start an additional worker process.

So: You don’t need a Procfile for default app configurations (like most Sinatra or Rails Apps for example).

More info here: https://devcenter.heroku.com/articles/procfile

Problem deploying simple ruby sinatra app on heroku

You're missing the top of the stack trace, but it looks like the problem is the require.

In config.ru change

require 'myapp2'

to

require './myapp2'

or

require File.expand_path("../myapp2", __FILE__)

Ruby 1.9.2 no longer has the current directory in the load path, so require 'myapp2' isn't able to find your app file which is in the same directory.

If this is working on your local machine, but not on Heroku, then you're likely using a different version of Ruby, probably 1.8.7. It would be a good idea to install 1.9.2 locally so that you're using the same version in development and production. Alternatively you could change the Heroku stack you're using; have a look at the Heroku stack docs

Application Error when deploying a simple rack application on heroku

It looks like you're not specifying the correct port for the app to run on. Try switching your Procfile to the following

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

See Deploy Sinatra app on Heroku and Deploying sinatra app (with config.ru) on heroku cedar stack for similar questions.

Can't get basic Ruby/Sinatra app working with Heroku?

/app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/main.rb:15:in `<class:Application>': missing argument: -p (OptionParser::MissingArgument)

That is the error it is giving you in the stack trace. When it is running bundle exec ruby app.rb -p there is no argument given for -p. You need something like bundle exec ruby app.rb -p 3000 (to run on port 3000). Perhaps the global variable $PORT is not getting defined?

EDIT

Though form heroku's docs on the Procfile:

You can reference other environment variables populated by Heroku, most usefully the $PORT variable, in the command.

Try doing a raise $PORT.inspect and then pushing to heroku. It will crash, but hopefully with a better picture of what it is trying to do.

Heroku Cedar - no static assets for mounted Resque front-end

Try removing the route and mounting the app in your config.ru. I'm using something along the lines of:

require ::File.expand_path('../config/environment',  __FILE__)
require 'resque/server'

run Rack::URLMap.new(
"/" => Rails.application,
"/resque" => Resque::Server.new
)

Heroku Cedar pure rack static site

Well, first, your config.ru is almost completely empty. Looks like you're following the same site structure as the Heroku tutorial, so start with a config.ru like this:

use Rack::Static, 
:urls => ["/stylesheets", "/images"],
:root => "public"

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

Since you are on Cedar, it is helpful to use a Procfile to start up your processes. So add a file called Procfile (no extension) to your root, and put the following inside it:

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

That should do it.

If you want to use Sinatra, Heroku has a step-by-step tuturioal for Ruby sites on Cedar: https://devcenter.heroku.com/articles/ruby

EDIT:

As it turns out, you're having line-endings problems in your config.ru. That's why GitHub is not displaying the file correctly. Your line endings are ^M, which are DOS/Windows/Mac OS 9 line-endings. That's why Ruby is throwing an error on line 2 - it's the first line break. Not sure what text-editor you are using, but it probably supports changing line endings. Switch them Unix, and all should work fine. If you're looking for a text editor that can do this, check out Sublime Text 2. The line-endings functionality is in the "View" menu.

Since you are building a pure Rack app, you actually don't need a Procfile, since the default Heroku Cedar buildpack will detect the config.ru for you. However, the Procfile comes in handy once you start using other frameworks (like Sinatra). Plus, if you are on a Mac, you can use Foreman to simulate Heroku's spin-up process. Note that Profile is without an extension and with a capital "P".

My bundler command is failing to load in my Sinatra app deployed in Heroku and thus causes it to crash

Identified Problems

You have a number of issues, but the largest is that you're attempting to run SinatraApp rather than run Sinatra::Application. This is most likely what's causing the app to crash, and the correct invocation is in both the Heroku and Sinatra documentation.

Furthermore, the Sinatra README recommends using the thin web server. Heroku recommends using a Procfile that explicitly defines the web server invocation for most Ruby-based apps. Specifically, it says:

Regardless of the webserver you choose, production apps should always specify the webserver explicitly in the Procfile.

Below, I provide my own suggested configuration for Sinatra apps that's (very slightly) less minimalist than the one provided in the Heroku docs. Start there, then tune it to suit.

Use a Foreman Procfile to Start Sinatra on Heroku

First, make sure your application's Heroku stack includes the heroku/ruby buildpack. Then, use a foreman Procfile to start your Sinatra app using the thin web server. For example:

# 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"

You can probably get it working with other configurations, including the minimalist one suggested by Heroku, but this setup works reliably for a broad number of Sinatra applications on Heroku. Your mileage (and number of errors) with other configurations may vary.



Related Topics



Leave a reply



Submit