Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails bundle install production only

I'm still new to rails/ruby/bundler and am a little confused.

In our config/application.rb file there's this bundler segment:

if defined?(Bundler)            # If you precompile assets before deploying to production, use this line   Bundler.require(*Rails.groups(:assets => %w(development test)))   # If you want your assets lazily compiled in production, use this line   # Bundler.require(:default, :assets, Rails.env) end 

and in our Gemfile we use different groups, e.g.

group :development, :test do   gem "rspec-rails", ">= 2.7.0", :group => [:development, :test]   gem 'shoulda-matchers'   gem 'watchr'   gem 'spork', '~> 1.0rc'   gem 'spectator'                             gem 'debugger'   gem 'wirble' end 

But when I run RAILS_ENV=production bundle install (or bundle install --deployment), it still installs gems from the development/test group...

Why does this happens or how can I make this work properly?

like image 915
gingerlime Avatar asked Jun 06 '12 10:06

gingerlime


People also ask

What is bundle install without production?

Now, If I use following command: bundle install --without production. In above command, the --without production option prevents the local installation of any production gem means whatever gems are in the production group will not be installed -- which in our example is just one gem: pg .

How do I install bundles to install missing gems?

In the invoked popup, start typing bundler, select bundle install and press Enter . Select Tools | Bundler | Install from the main menu. Open the Gemfile, place the caret at any highlighted gem missing in the project SDK and press Alt+Enter . Select Install missing gems using 'bundler' and press Enter .

What is the goal of running bundle install?

When we run bundle install in a project , if there is no Gemfile. lock exist, Bundler will fetch all remote sources, resolve dependencies and install all needed gems.


2 Answers

Take a look at --without option:

bundle install --without development test

By default Bundler installs all gems and your application uses the gems that it needs. Bundler itself knows nothing about Rails and the current environment.

like image 63
Simon Perepelitsa Avatar answered Dec 09 '22 14:12

Simon Perepelitsa


An alternative solution is to use the bundle-only ruby gem. It can be used as follows:

> gem install bundle-only > bundle-only production 

This library does not pollute your bundler configs or augment Gemfile.lock; it is a simple alternative to the built in bundle --without every other group option that bundler provides.

like image 28
Tom Lord Avatar answered Dec 09 '22 13:12

Tom Lord