Skip non-development environment gems installation - ruby-on-rails

I have some gems needed outside development environment. So I moved them to the corresponding group in Gemfile as follows:
group :staging, :production do
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0'
gem 'ruby-oci8', '~> 2.2', '>= 2.2.7'
gem 'aws-sdk-s3', '~> 1.48', require: false
end
Nevertheless, after cloning the project, when running bundle install it still requires to install ruby-oci8. What am I missing?

By default, bundle install will install all gems in all groups in your Gemfile, except those declared for a different platform.
However, you can explicitly tell Bundler to skip installing certain groups with the --without option. This option takes a space-separated list of groups.
While the --without option will skip installing the gems in the specified groups, it will still download those gems and use them to resolve the dependencies of every gem in your Gemfile.
This is so that installing a different set of groups on another machine (such as a production server) will not change the gems and versions that you have already developed and tested against.
ref: https://bundler.io/man/bundle-install.1.html

Related

Libv8 & therubyracer - Full install on every new site deployment?

I have a Ubuntu 12.04 server and several rails 3.2.14 sites on it. Every time I do a new site deployment (via capistrano) the first install takes 20 - 30 minutes because it does a full install of libv8, even though I have already installed the libv8 gem on the machine (and see it when I do a gem list).
I've tried the binary version and tried changing versions of therubyracer.
Here's therubyracer part of my Gemfile
group :assets do
gem 'sass-rails', '~> 3.2.6'
gem 'coffee-rails', '~> 3.2.2'
gem 'uglifier', '>= 1.0.3'
gem 'therubyracer', '~> 0.12.0'
end
I've turned on verbose output in Capistrano and here's where it hangs up for ~20 minutes
** [out :: 198.58.99.7] Installing libv8 (3.16.14.3)
Any suggestions? Really tired of new sites taking this long to deploy.
As I said in my comment, bundle with the --deployment flag (as Capistrano does) installs gems into a your_app/shared/bundle. One of the reasons for this isolation and location is because the user you're deploying with may not have access to install gems to a system location, and more reasons described here (under the Deploying Your Application heading).
I believe there are ways to force bundler to use the system gems but I don't have any first hand experience of it; see here.
There's probably a conflict in dependencies in your Gemfile.
Remove the version constraint for therubyracer in your Gemfile and bundling should be much faster.
gem 'therubyracer'

Rails - how do gems relate to doing 'bundle'

I'm learning Ruby on Rails from Michael Hartl's website. I have a Gemfile that looks like this:
source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
.
.
.
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Why is this sequence of commands correct:
`$ bundle install --without production`
`$ bundle update`
`$ bundle install`
Shouldn't it first be bundle update then bundle install --without production. Why call bundle install twice? I think the second call is redundant.
Why is this sequence of commands correct:
$ bundle install --without production $ bundle update $ bundle install
Without context, it's difficult to answer this—but one can intuit from the commands that it probably doesn't appear as one string of commands to be executed dutifully.
bundle install --without production installs exactly the versions in your lockfile, skipping any gems in a production group or with a production tag. This allows you to install only what you need to test and develop your application. (e.g., you probably don't want to waste lines with your logging service or pollute your monitoring service.) More importantly, this gives you a known-good working state for development on any machine you use.
bundle update updates the lockfile with permissible newer versions of the gems in the Gemfile. This can and will break your application if the Gemfile has not been well-crafted and versions of your dependencies have changed in the mean time. (So to answer your other question, no, you wouldn't run an update before an install.)
bundle install is most likely there to illustrate the correct command for deploying your production application: It wouldn't make any sense to skip the production gems and immediately turn around to install the production gems.
Where actually are these stuff being downloaded saved? Where are they
being installed? On my computer? I never got where they actually go or
hide. Maybe in my applications folder? But where exactly?
On your computer, in your Ruby installation. Ruby, like Perl and Python, maintains a portion of its directory structure specifically for add-on libraries.
In Ruby 2.0.0, for example, they live someplace similar to [RUBY_ROOT]/lib/ruby/gems/2.0.0/gems. For very specific purposes, it's also possible to install them locally in your Rails application's directory.
My recommendation is
1) Just do bundle, forget the rest. Not important to your learning
2) bundle install
OK, so for whatever version of ruby you are currently using this will take your Gemfile and get the right versions of those gems from rubygems.org (the site). and then install those gems on your machine for version of ruby that you are using if that version doesn't already exist on your machine. If the version exist, no download is needed, the gem version will be able to be immediately included, e.g. when offline.
If you switch ruby version then you'll usually need to bundle install again to get the right versions of those gems for the version of ruby that is currently being used on your machine.
If you use a tool such as rvm to manage your ruby versions then this is as simple as:
cd the_application_directory_for_your_rails_application
rvm use 1.9.3
bundle install
then to switch to ruby 2.0
rvm use 2.0
bundle install
You can specify specific ruby versions with
rvm use 1.9.3-p448 # e.g. for the -p448 version
You can see the 'currently available' ruby versions on your machine with
rvm list rubies
You can install a specific ruby with, e.g.
rvm install 1.9.3-p194

Why does 'bundle' install production gems on my development machine?

Gemfile says:
gem 'sqlite3', :groups => [:development, :test]
gem 'mysql2', :group => :production
yet when I type bundle install on my development machine ALL gems are installed.
What's wrong with my setup?
The point of Bundler is to create a consistent gem environment across deployments. Gems, unfortunately, can interact even if they aren't loaded or required. So for maximum consistency, all gems should be installed, even if they aren't all required.
However, if you don't want all gems installed all the time, you can use the bundle install --without option.

Rails bundler doesn't install gems inside a group

I have several gems including ruby-debug in a bundler group called :development. When I run the bundle command, these gems are ignored and it only installs the gems that are not in any group. How can I make sure bundler doesn't ignore the gems in the :development group?
Edit: This is what my Gemfile looks like.
source 'http://rubygems.org'
gem 'rails', '3.0.1'
# Auth gems
gem "devise", "1.1.3"
gem "omniauth"
# Bundle Mongoid gems
gem "mongoid", "2.0.0.beta.19"
gem "bson_ext"
# Asset gems
gem 'jquery-rails'
gem "jammit"
# Controller gems
gem 'inherited_resources', '1.1.2'
# View gems
gem 'haml'
gem 'formtastic', '~> 1.1.0'
# Nokogiri
gem "mechanize"
gem "json"
group :development do
gem "ruby-debug"
gem 'compass'
gem 'compass-colors'
gem 'pickler'
gem 'haml-rails'
gem 'rails3-generators'
gem "hpricot"
gem "ruby_parser"
gem 'fog'
end
Within a term session, it remembers the without option. If you first ran
bundle install --without development
it remembers that you did this and will automatically repeat this for the next
bundle install #remembers and includes --without development
running something else, like bundle install --without nothing should clear the cache. Am I right?
update 20150214: This is fixed in bundler 2.0, according to issue referenced in comment by #Stan Bondi (https://github.com/bundler/bundler/issues/2862). Thanks Stan.
If you are using rails, there will be a file config written into a hidden dir called .bundle in your rails root directory:
.bundle/config
This file, in my case, held exactly the without settings.
So I just deleted the .bundle directory:
rm .bundle -r
After that:
bundle install worked again as expected.
Using: bundler (1.5.2)
I had the same issue and --with flag worked for me. You need to pass group name, which you want to include. Like that:
bundle install --with development
gem 'aws-s3'
gem 'paperclip'
group :test do
gem 'rspec'
gem 'waitr'
gem 'faker'
end
gem 'rest-client', :group => :development
gem 'cucuber-rails', :groups => [:development,:test] (cucuber-rails gems comes under both group)
bundle install --without development #(ignore development group gems)
bundle install #(still bundle remembers --without development so result is still ignore development groups it will not install all gems)
bundle install --without nothing #(just clearing cache, now all the gems to be loaded into the ruby loadpath)
More
In fact Rails loads the :development group automatically when in development environment. Check whether Rails.env in you App really returns "development".
More Information about groups in Bundler:
http://gembundler.com/groups.html
I had a similar problem - thin in staging ignored - and the solution was to put it out if staging into the 'global' space:
gem 'thin'
group :production do
gem 'puma'
end
I've faced the same issue with bundler 2.1.4 When I checked my .bundle/config it has
---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_WITHOUT: "development:test:build"
Remove groups from there and add BUNDLE_WITH to your groups.
BUNDLE_WITH: "development"
I've removed the ~/.bundle/config. but there was a file in my project directory. .bundle/config. Local directory files have precedence over the main config files.
If you can't figure out the reason, then you can just create a file in your project directory .bundle/config. and add this content there
BUNDLE_WITH: "development:test:anyGroupYouWant"

Groups in a Gemfile in Rails 3?

In my Gemfile in Rails I have these groups:
group :development, :test do
gem "capybara"
gem "database_cleaner"
gem "spork"
gem "launchy"
end
group :bdd do
gem "cucumber-rails"
gem "rspec-rails"
end
What does this mean?
From http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/:
Specifying groups allows you to do two things. First, you can install
the gems in your Gemfile, minus specific groups. For instance, Rails
puts mysql and pg in a database group so that if you’re just working
on ActionPack, you can bundle install --without db and run the
ActionPack tests without having to worry about getting the gems
installed.
Second, you can list specific groups to autorequire using
Bundler.require. By default, Bundler.require requires all the gems in
the default group (which is all the gems that have no explicit group).
You can also say Bundler.require(:default, :another_group) to require
specific groups.
Grouping your dependencies allows you to perform operations on the entire group. See: http://gembundler.com/v1.3/groups.html
Answer updated to Bundler 1.3 -> http://gembundler.com/v1.3/groups.html

Resources