I have a small web app, which uses a bunch of gems. Some of them are only used for test
and development
environments. Now, when I try to start unicorn on the production server using the following command, it fails.
unicorn_rails -E production -D -c config/unicorn.rb
The error I see in the log files is:
Refreshing Gem list Could not find gem 'spork (>= 0.9.0.rc2, runtime)' in any of the gem sources listed in your Gemfile. Try running `bundle install`.
I've pasted my gemfile below:
source 'http://rubygems.org' gem 'rails', '3.0.1' gem 'unicorn' gem 'mongoid', '>= 2.0.0.beta.19' gem 'devise' gem 'cancan' gem 'haml', '>= 3.0.0' gem 'bson' gem 'bson_ext' gem 'formtastic' gem 'bluecloth' group :production do gem 'capistrano' end group :development do gem 'haml-rails' gem 'hpricot', '0.8.2' gem 'ruby_parser', '2.0.5' gem 'less' gem 'rspec-rails', '>= 2.0.1' end group :development,:test do gem 'spork', '>=0.9.0.rc2' gem 'mongoid-rspec' end group :test do gem 'factory_girl_rails' gem 'autotest' gem 'cucumber-rails' gem 'cucumber' gem 'capybara' gem 'shoulda' gem 'database_cleaner' gem 'test_notifier' gem 'rspec', '2.0.1' gem 'launchy' end
Bundler is supposed to detect the right environment and ignore the other gems, right? Right now, I am deleting all the lines which are not in the default group on the server to get this working, but that's an ugly hack.
After a lot of digging I found the fix for this issue. All I had to do was run bundle install --without development test
before starting the server. This adds a .bundle/config
file in the rails root with the line BUNDLE_WITHOUT: test:development
. Now whenever you run bundle install
or start the server it'll ignore those groups.
From the documentation
The Bundler CLI allows you to specify a list of groups whose gems bundle install should not install with the --without option. To specify multiple groups to ignore, specify a list of groups separated by spaces.
bundle install --without test bundle install --without development test After running bundle install --without test, bundler will remember that you excluded the test group in the last installation. The next time you run bundle install, without any --without option, bundler will recall it.
Also, calling Bundler.setup with no parameters, or calling require "bundler/setup" will setup all groups except for the ones you excluded via --without (since they are obviously not available).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With