Sinatra + Heroku + Datamapper deploy issues with dm-sqlite-adapter - ruby

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.

Related

No such file to load when requiring jruby pg on Heroku

I'm looking to use the jRuby pg gem in a jRuby application. The gem runs fine locally, but when run on heroku it is unable to load the pg gem.
LoadError: no such file to load -- pg
require at org/jruby/RubyKernel.java:1071
require at /app/vendor/ruby-1.9.3-jruby-1.7.19/lib/ruby/shared/rubygems/core_ext/kernel_require.rb:54
(root) at text.rb:19
My Gemfile is:
ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.19'
gem 'pg', '0.17.1', :platform => :jruby, :git => 'git://github.com/headius/jruby-pg.git', :branch => :master
Heroku bundle show returns:
Gems included by the bundle:
* pg (0.17.1 c236a38)
Heroku ruby -v returns:
jruby 1.7.19 (1.9.3p551) 2015-02-06 fffffff on OpenJDK 64-Bit Server VM 1.8.0_60-cedar14-b24 +jit [linux-amd64]
text.rb contains:
require 'rubygems'
require 'pg'
puts "cool!"
So far I have:
run bundle locally and repushed
run bundle install locally and repushed
cleared Gemfile.lock repushed and then run bundle on heroku
updated heroku toolbelt
updated ruby gems
checked to see that I'm running the same version of jruby locally and on heroku
uninstalled pg gem and reinstalled
required rubygems in the text.rb file
required the absolute path of pg.rb on heroku, this resulted in an unable to load pg_ext error
In order for this to work, you'll need to prefix your Procfile command with bundle exec (because it's a non-standard gem Heroku can't put it on the path automatically).
For example:
test: bundle exec ruby text.rb
However, this will add a bit of overhead to your JRuby startup time because Bundler has to launch two JRuby processes (one for itself, and then another with the correct gem context).
Another option is to use the activerecord-jdbcpostgresql-adapter, which is more widely adopted.

heroku run rake db:create fails with Could not find gem 'pg..., but the database is mysql2 (not postgresql)

I receive the following error when I run heroku run rake db:create:
Running `rake db:create` attached to terminal... up, run.6027
Could not find gem 'pg (>= 0.11.0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
In the config/database.yml I'm using the default mysql2 database:
production:
adapter: mysql2
database: redmine
host: localhost
...
development:
adapter: mysql2
...
test:
adapter: mysql2
...
So I guess 'pg (>= 0.11.0) ruby' does not need to be installed. Am I wrong?
I'm using Windows XP. It is the first time I use Ruby.
UPDATE 1
I forgot to say bundle install finished correctly without errors.
On the other hand, Gemfile has the following code:
adapters.each do |adapter|
case adapter
when 'mysql2'
gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
...
when /postgresql/
gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw]
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
...
So again, I guess it should never enter in when /postgresql/ when the command heroku run rake db:create is executed. Am I right?
See the discussion above... This is a Heroku application and it needs a database configured or it is going to try and force Postgres as a dependency to help you out.
You need to do bundle install before running the rake task for db creation and fulfill all gem dependencies. This is required even though you are using mysql and not postgres because the 'pg gem' is specified in the Gemfile and you have to make sure that all gem dependencies in your Gemfile are made available to your application by running the bundle install commmand.
As in your case you are using mysql, you do not require the 'pg gem' and can remove or comment it in the Gemfile.

Heroku with ruby 1.9.3 causing many different crashes

I go to redeploy my heroku apps with a new gem in Gemfile and it crashes on startup
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require': libruby.so.1.9: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/1.9.1/gems/bcrypt-ruby-3.0.1/lib/bcrypt_ext.so (LoadError)
This is happening no matter what branch I deploy (old stable ones...) and only fixes by doing a heroku rollback.
I believe this is caused by heroku recently updating their ruby 1.9.3 because I was having this issue Heroku app crashes with 'libruby.so.1.9: cannot open shared object file' . Removing the nokogiri gem stopped the exception I was getting but then there's still this. More similar errors occur when I add new gems.
The whole problem was solved by deploying to a new heroku app but that's not something I can just do on my production server.
Any ideas on fixing the issue or somehow "refreshing" my app?
my gemfile:
source "https://rubygems.org"
ruby "1.9.3"
gem "rails", "3.2.3"
gem "thin"
# Bundle edge Rails instead:
# gem "rails", :git => "git://github.com/rails/rails.git"
gem "mongoid"
gem "devise"
gem "haml"
gem "sass"
gem "exceptional"
gem "kaminari"
gem "mongoid_search"
#gem "nokogiri"
gem "bson_ext"
gem "heroku-mongo-backup"
gem "aws-s3"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem "haml-rails", "~> 0.3.4"
gem "sass-rails", "~> 3.2.3"
gem "coffee-rails", "~> 3.2.1"
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem "therubyracer", :platform => :ruby
gem "uglifier", ">= 1.0.3"
end
gem "jquery-rails"
group :test do
gem "mongoid-rspec"
end
# To use ActiveModel has_secure_password
# gem "bcrypt-ruby", "~> 3.0.0"
# To use Jbuilder templates for JSON
# gem "jbuilder"
# Use unicorn as the app server
# gem "unicorn"
# Deploy with Capistrano
# gem "capistrano"
# To use debugger
# gem "ruby-debug19", :require => "ruby-debug"
#
group :development do
gem "letter_opener"
end
Just FYI,
After contacting the Heroku support about this issue, you should follow these 3 simple steps:
Install this heroku-repo plugin: heroku plugins:install https://github.com/lstoll/heroku-repo.git
Run the following command: heroku repo:purge_cache
Deploy your app again.
Hope that helps!
This happened to me yesterday as well, was definitely something to do with Heroku.
I found fix and discussion on Twitter: https://twitter.com/bcardarella/status/256822171979100161
Just force-clear the gem file cache(clear gemfile, deploy, restore and deploy) and the app would start smoothly again.

Rails Heroku application error

I try to push my rails application to heroku but encountered the following error
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
Because I am using sqlite3
A search on the web show I should do the following
heroku rake db:create
heroku rake db:migrate
the heroku rake db:create failed by complaining
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
The command gem install activerecord-postgresql-adapter failed and complains
ERROR: Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository
ERROR: Possible alternatives: activerecord-postgis-adapter, activerecord-jdbcpostgresql-adapter, activerecord-postgresql-cursors, activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter
Then I searched the web again and followed the http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development suggestion to change
gem 'sqlite3'
to
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
and run
bundle install --without production
however this did not solve the problem
another source say I need to do like
group :production do
gem 'therubyracer-heroku', '0.8.1.pre3'
gem "pg"
end
This also failed to solve the issue
I have postresql installed on my system.
So what hell is the problem?
The key thing here is that the pg gem is required to run against the Postgres database that you end up using when you deploy to heroku (http://devcenter.heroku.com/articles/database)
Ideally, you want to be running Postgres locally so that you're not seeing any differences between development and production from a database standpoint.
If you want to stick with things how you have them simply adding gem "pg" to your Gemfile should fix this.
Once added, run:
bundle install
git add .
git commit -am "Added PG to Gemfile"
git push heroku master
heroku rake db:migrate
Please following steps for deploy on heroku server
First please remove the gem ='sqlite3' from Gemfile and add gem = 'pg'
Run this command on Project path: bundle install
git add .
git commit -am "add pg on gem file"
git push heroku master

Sinatra, Bundler and BUNDLE_PATH confusion

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

Resources