I'm trying to deploy to heroku a modular sinatra app that works fine locally. This is in the heroku logs:
2020-12-28T21:05:15.907560+00:00 heroku[web.1]: Starting process with command `bundle exec rackup config.ru -p 58645`
2020-12-28T21:05:18.738254+00:00 app[web.1]: bundler: failed to load command: rackup (/app/vendor/bundle/ruby/2.7.0/bin/rackup)
2020-12-28T21:05:18.738283+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?
The command bundle exec rackup config.ru -p 58645 runs fine locally.
This is my config.ru
require_relative './config/environment.rb'
use EntreeController
use UserController
run ApplicationController
and environment.rb
APP_ENV = ENV["RACK_ENV"] || "development"
ENV['SINATRA_ENV'] ||= "development"
require 'require_all'
require 'bundler/setup'
Bundler.require(:default, ENV['SINATRA_ENV'])
require_all 'app'
require_all 'app/models'
require_all 'app/helpers'
And the Procfile:
web: bundle exec rackup config.ru -p $PORT
I'll post my solution, if ever someone bumps into the same problem. I had followed the indication on the Rakefile here : https://github.com/sinatra-activerecord/sinatra-activerecord.
One solution was to entirely deleted the Rakefile when deploying to Heroku. The other solution is to put only this in the Rakefile :
require "sinatra/activerecord"
require "sinatra/activerecord/rake"
require "./app" # or whereever your app is
Switching to Bundler 2.1.4 solved the problem in my case.
For the longer run one will have to install bundler 2.1.4 and use it, but for the sake of test I just manually edited that line in Gemfile.lock:
BUNDLED WITH
2.1.4
I was using Ruby 2.7.2 and Bundler 2.2.8 — Heroku buildpack provided Bundler 2.1.4.
Funny that Heroku’s Bundler bugs list had nothing about 2.2.8.
Related
having trouble pushing my sinatra app to heroku based on the current setup. I have looked through all of the docs on heroku to figure this out but alas, i'm without resolution and continue to get the following error. No default language could be detected for this app.
app
--.git
-- public
-- views
- app.rb
- config.ru
- gemfile
- Gemfile.lock
- Procfile
- foo.csv
Procfile
web: bundle exec ruby app.rb -p $PORT
config.ru
require './app'
run Sinatra::Application
Gemfile
source 'https://rubygems.org'
ruby "2.4.0"
gem 'sinatra'
app.rb
require 'rubygems'
require 'sinatra'
require 'csv'
Tilt.register Tilt::ERBTemplate, 'html.erb'
set :public_folder, 'public'
get "/" do
erb :index
end
Update
Still not quite sure what the issue was here. I ended up grabbing the following sinatra/heroku shell from github, and replaced it with the assets from my app. Once I ran a bundle and pushed to heroku everything ended up working. I'm sure the issue is structurally nuanced and can be pulled from a deeper look at the working setup, for now - i'm just happy it's working.
https://github.com/runemadsen/Sinatra-Heroku-Template
im developing a application in ruby with sinatra. evrything worked finely until i put it on heroku. heroku gives me internal server error but no error code ):
currently my workstation is a windows computer.
my log loooks like this: http://i.imgur.com/Xd3QAms.png
config.ru
require 'tilt/haml'
require 'sass/plugin/rack'
require '4c96748'
run Sinatra::Application
gemfile
source 'https://rubygems.org'
ruby '2.2.3'
gem 'sinatra', '1.1.0'
procfile
web: bundle exec rackup config.ru -p $PORT
4c96748.rb
require 'sinatra'
require 'tilt/haml'
get '/' do
haml :index
end
pleaase help me, what do i need to do?
try following in your 6c96748.rb
require 'rubygems'
require 'sinatra'
require 'haml'
get '/' do
haml :index
end
From your logfile:
LoadError - cannot load such file -- haml
There is no Haml installed on Heroku. Every dependency you need on Heroku needs to be in your Gemfile.
Add the following Line to Gemfile:
gem 'haml'
Don't forget to run bundle before commiting your changes and pushing to heroku again.
(As a sidenote, your Sinatra version is quite outdated. The current version is 1.4.6 (see https://rubygems.org/gems/sinatra))
For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres here. Note, that this happens when I open any URL - not during the git push itself.
I built a default facebook app.
The Gemfile:
source :gemcutter
gem "foreman"
gem "sinatra"
gem "mogli"
gem "json"
gem "httparty"
gem "thin"
gem "data_mapper"
gem "heroku"
group :production do
gem "pg"
gem "dm-postgres-adapter"
end
group :development, :test do
gem "sqlite3"
gem "dm-sqlite-adapter"
end
Datamapper setup:
# Setting up the database
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/data/mydatabase.db")
Relevant log fragment, when any URL is opened:
Starting process with command `bundle exec thin -R config.ru start -p 34984`
2012-01-18T15:11:55+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-sqlite-adapter (LoadError)
2012-01-18T15:11:55+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `load_adapter'
Tried related solutions, but with no help so far.
BTW: bundle install says Using do_postgres and Using dm-postgres-adapter. Am I missing something about Datamapper setup?
Well, too many Rails apps on Heroku, I took the shared db presence for granted. heroku config showed neither DATABASE_URL or SHARED_DATABASE_URL set.
Issuing heroku addons:add shared-database:5mb solved the problem.
Strange, that the db wasn't automatically added, despite having 'pg' gem in Gemfile.
Quote from http://devcenter.heroku.com/articles/cedar:
A Heroku shared PostgreSQL database (shared-database:5mb) will be
automatically added to your app in any of the following cases:
The app is a Rails application
The pg gem is specified in the Gemfile
Try doing DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://user:password#hostname/data/mydatabase.db') instead. Heroku is probably looking at the protocol, and therefore requiring SQLite’s dependencies.
I am having trouble configuring Sinatra to use Bundler. I am confused as to where Gems should be being installed? I've read both this question and this documentation.
My Gemfile looks like:
source "http://rubygems.org"
gem "sinatra"
gem "amazon-ec2"
My config.ru looks like:
require "rubygems"
require "bundler"
Bundler.setup
require "application"
run Sinatra::Application
My application.rb looks like:
require "rubygems"
require "sinatra"
require "AWS"
#... rest of application
Now, when I run bundle install everything works correctly and Gems get installed into ~/.bundle/ in my home directory. Yet, in my app if I have a look at .bundle/config it shows:
---
BUNDLE_WITHOUT: ""
BUNDLE_PATH: vendor/gems
Sure enough, when I start up the app (using Passenger by the way) it says:
Could not find gem 'amazon-ec2 (>= 0, runtime)' in the gems available on this machine. (Bundler::GemNotFound)
Clearly bundle install is installing Gems in a different place to where Sinatra expects them to be. Does that mean I have to use bundle install vendor or reconfigure something else so that the application expects the Gems to be in ~/.bundle?
About a year after #aaronrussell 's initial posting, I hit the same problem with Passenger, Nginx, Bundler, Sinatra. I got through it by running this on production:
bundle install --deployment
Bundled gems go in ./vendor/bundle
Here are some details on bundler deployment mode
I'm wondering how one can use Bundler with Sinatra. The idea is to use the gems that Bundler downloads inside the .gems folder.
Inside your Sinatra app, you just have to require the bundler setup:
require "bundler/setup"
require "sinatra"
get "/" do
"Hello world!"
end
Alternatively, if you don't want to add the additional require "bundler/setup" at the top of your app, you can instead invoke sinatra via bundle exec (e.g. bundle exec ruby myapp.rb)
This assumes that you have a Gemfile in the root of your application. It might look like this:
source "http://rubygems.org"
gem "sinatra"
This also assumes that you've already installed bundler (gem install bundler) and that you ran bundle install to install all the gem dependencies.
I believe the best way is described here on EngineYard blog:
# This makes sure the bundled gems are in our $LOAD_PATH
require File.expand_path(File.join(File.dirname(__FILE__), 'vendor', 'gems', 'environment'))
# This actually requires the bundled gems
Bundler.require_env
class MyApp < Sinatra::Base
# stuff
end
As my original answer was quite old but there seems to be still attention to this topic here's the latest version of bundler/sinatra setup which will cover most of the use case:
A minimal config.ru
require './my_sinatra_app'
run MySinatraApp
An environment env.rb file that requires all the bundled gems (also supports loading the current environment's group):
require 'bundler/setup'
APP_ENV = ENV["RACK_ENV"] || "development"
Bundler.require :default, APP_ENV.to_sym
Then your app file (requiring the environment) with your sinatra app (Sinatra::Base):
require_relative 'env'
class MyApp < Sinatra::Base
get "/" do
"hello world"
end
end
Start your development server with rackup, and Sinatra will be loaded via Bundler, your app will be accessible from http://localhost:9292.
$ rackup
or bundle exec rackup if needed
Make sure you have a Gemfile like the following one and you run the bundle command before starting the app
source "https://rubygems.org"
gem "sinatra"
gem "puma" # a better rack server than the default webrick
+1 for the guide on the bundler website, but if you have a simple app and use Sinatra's dsl at the top level, then you need to do the following:
in your Gemfile (tell bundler not require sinatra):
gem 'sinatra', :require => false
and in the app's file (explicitly require sinatra):
require 'rubygems'
require 'bundler'
Bundler.require
require 'sinatra'
get '/' do
'hello world'
end
To use bundler with a Sinatra application, you only need to do two things. First, create a Gemfile.
gem 'sinatra'
Then, set up your config.ru file to load the bundle before it loads your Sinatra app.
require 'rubygems'
require 'bundler'
Bundler.require
require './my_sinatra_app'
run MySinatraApp
Start your development server with rackup, and Sinatra will be loaded via Bundler.
rackup
source bundler docs