Can you deploy a Rails3 app using Bundler\'s Gemfile WITHOUT running bundle install
... i.e. just by copying a rails project directory to the appropriate
Some other rails devs and I were discussing how to effectively freeze gems in Rails 3 and we worked out this solution. This is along the lines of what @asymmetric proposed, but different in some key ways. As I later discovered from the gemfile man page, this approach also suffers from the same limitation that @indirect warned of with bundle install --deployment
, in that your gems must either be pure ruby (no native compilation), or these steps must be done on an identical architecture to your stage and prod servers.
Ok, now that we have the preliminaries out of the way, let's see about "freezing" some gems into Rails 3...
First, start with a clean environment:
$ rvm gemset use fresh
$ rvm gemset empty fresh
$ gem install rails
$ rails new strawman
$ cd strawman/
Next, install the gem you want to use:
$ gem install condi
Next, create a vendor/gems
directory and unpack the gem within it:
$ mkdir vendor/gems
$ cd vendor/gems
$ gem unpack condi
Unpacked gem: '/tmp/strawman/vendor/gems/condi-0.0.6'
OPTIONAL:
If your gem doesn't have a .gemspec file with it (i.e. the spec is part of the contained Rakefile build), Bundler may not be able to load it correctly with the :path statement. In this case, you have to output the gemspec from the gem file using:
$ gem specification /tmp/condi-0.0.6.gem > condi-0.0.6/condi.gemspec
Or if you already have the gem installed locally, you can:
$ gem specification condi -v=0.0.6 > condi-0.0.6/condi.gemspec
Now, update the Gemfile
with the line:
gem 'condi', '0.0.6', :path => 'vendor/gems/condi-0.0.6'
NOTE: "Unlike :git, bundler does not compile C extensions for gems specified as paths." [man gemfile] So this only works for pure ruby gems without native extensions! Be warned!
Next, uninstall the gem from your gemset:
$ gem uninstall condi
Successfully uninstalled condi-0.0.6
And returning to the rails root environment, try to run the rails console:
$ cd ../..
$ rails c
Loading development environment (Rails 3.1.3)
1.9.3-p0 :001 >
Success!! Your pure ruby gem is now effectively frozen in a Rails 3 app.