Explanation for "bundle install --deployment" - ruby-on-rails

I'm trying to understand some of the details behind bundling for deployment that I can't wrap my head around. I've read a few posts on here such as this one:
What does Rails 3's Bundler "bundle install --deployment" exactly do?
and I feel I understand what it should do. On my computer, I ran bundle install initially and have been developing a project. However, I wanted to see if I could run it in deployment just to get a feel as to how a production server like Heroku sets up the application.
Therefore, I started by running bundle install --deployment, which correctly installs all my gems into the local vendor/bundle local directory. However, when I run bundle show [GEM], I'm still seeing the path to my system gem. I feel it should be showing a path to the local folder, but it's not.
Can someone clear up on what my misconception is?

Have a look at the description of the two on Bundler's site.
Running bundle install --deployment is to be run in the production environment, but will grab the gems from rubygems when run. Read more here under the 'Deploying Your Application' heading for the purpose of the --deployment flag.

Related

No gem file in my Ruby on Rails project, bundle install/update doesn't work?

I am working on a project in which Gemfile is not present.
That project is working fine on production server having Apache with passenger.
But, Bundle install and bundle update does not work when I try try to start project in development environment. How to get that project working in development environment?
Unless someone from systems engineering can tell you, where the Gems were defined, You can reverse engineer a Gemfile from the contents of Gemfile.lock.
Or you can try to run your project by using this command, after you copied the Gemfile.lock from production, also put an empty Gemfile, as the bundler requires it.
bundle install --deployment
see this answer, but sooner or later you will need the Gemfile.

Rails Bundle Options for Getting Gems back into your Local Application

I ran bundle --without development on my machine and now I want to include the dependencies in my development group in my local rails app.
I ran bundle thinking it would including everything again including development, but I receive this message Gems in the groups development were not installed still. Can you tell me the option I need to pass into the bundle command to get the development gems back into my application? I tried running bundle --include development with no luck.
Can you also tell me where you found the option (if thats the solution)? I can't seem to locate a list of bundle options.
If you run
bundle help install
then both the with and without options are documented. Note that without is listed as being a "remembered option" i.e. it is persisted for subsequent calls.
Remembered options are stored in .bundle/config at the root of the project. You can either edit this file directly or view them using
bundle config
Which will also take into account user level configuration or environment variables that affect bundler
I was surprised to confirm this behavior. It seems like the without --development flag is saved, so even if you rm Gemfile.lock, running bundle again will not install the development group. bundle update also doesn't work.
You were close, though, with bundle --include development.
What works is bundle --with development. You don't need to delete your Gemfile.lock before doing this.

Rails 3 and Bundler. How to deploy and NOT package gems

I'm having lots of problems trying to deploy using capistrano. I keep on getting errors about libv8 not in any of the sources.
Could not find libv8-3.11.8.13 in any of the sources
Here https://github.com/cowboyd/libv8/issues/56 tells you that you could "not to use packaging", that way, the deployed app won't use the bundle package.
How can I deploy and use the gems NOT IN THE BUNDLE PACKAGE? I want the app do run bundle everytime I deploy instead or to just run bundle when the Gemfile has changed.
This is how I got it working: https://github.com/cowboyd/libv8/issues/77#issuecomment-12711634
I'm doing development on a mac and deploying to a red hat server. It seems Rails needs a OS, platform-specific version of the gem. So when I'm running bundle on my development machine (mac) and then deploy it with capistrano to the production server (red hat), it won't work.
What I ended up doing is...
manually download the libv8 gem I needed from http://rubygems.org/gems/libv8
copy the downloaded gem to the vendor/cache folder
then deployed the app (cap deploy:cold)
and it worked.
If I understand your question correctly it sounds like you're missing the bundle capistrano task. See https://github.com/carlhuda/bundler/blob/master/lib/bundler/capistrano.rb for more. You should be able to "require 'bundler/capistrano'" to your capistrano deploy.rb file so that bundle is run on every deploy.

Bundler and hidden gems

I have an interesting error when installing gems directly from github (:git => 'whatever').
Firstly, when I remove all gems and run bundle install command, I get the following:
Installing gem1
Installing gem2
Using gem3 (the one from github)
Then when I want to check what I've got I see the following by using gem list:
gem1 (x.x.x)
gem2 (y.y.y)
No gem3... now, looking closer to the file system, I see the following:
ls -l ~/.rvm/gems/ruby-1.9.3-p125/gems
gem1
gem2
So where is gem 3? Not where I'm expecting it to be:
ls -l ~/.rvm/gems/ruby-1.9.3-p125/bundler/gems
gem3-213213213
So it goes under bundler/gems and is not visible to gem list... and by Capistrano deploy, which gives me following:
git://github.com/author/gem3.git (at master) is not checked out. Please run `bundle install`
I'm more worried about Capistrano unable to deploy... Anyone has any clues?
Bundler gets its gems from various sources on your system. As long as they are the correct version, it will pull them in.
When deploying, it has more strict/conservative behavior.
From bundle help install, in the section about Deployment Mode, which is used when the --deployment flag is specified:
Gems are installed to vendor/bundle not your default system loca-
tion
In development, it's convenient to share the gems used in your
application with other applications and other scripts run on the
system.
In deployment, isolation is a more important default. In addition,
the user deploying the application may not have permission to
install gems to the system, or the web server may not have permis-
sion to read them.
As a result, bundle install --deployment installs gems to the ven-
dor/bundle directory in the application. This may be overridden
using the --path option.

Local copy of Rails in a rails application

I recently upgraded a rails project I am working on from 2.0.5 to 2.3.2. I noticed that there was a local copy of the 2.0.5 rails files in vendor/rails and I was wondering should I put a local copy the 2.3.2 rails files in there too or just leave them out? What is considered a better practice?
Yes. The copy of Rails that sits in vendor/rails is actually used in preference to the Rails gems installed system-wide—in other words, though you upgraded your Rails install, your app is actually still running on 2.0.5.
The vendor/rails directory exists so you can "freeze" your app to a specific version of Rails, thus making it less vulnerable to changes in the configuration of the machine it's running on. This is so darned useful that there's an automated way to manage the directory. To delete the existing version of Rails sitting in vendor/rails, go to the root of your Rails project directory and do the following:
rake rails:unfreeze
To then install the most current Rails gems on your system into vendor/rails, do:
rake rails:freeze:gems
There are a few other things you can do with vendor/rails. Check out rake -T for a full list of commands.
P.S. If you ever hear someone talk about their Rails install being "vendored", this is what they mean.
In the meanwhile things have changed a little.
rake rails:freeze
and
rake rails:unfreeze
are deprecated. Instead you should use:
bundle install --path vendor/bundle
and
bundle install --system
to switch back.

Resources