6

I'm trying to vendorize my ruby application so that I don't have to manually install any gems on the server and can deploy my application as an rpm in our puppet setup.

This nearly works, except despite me adding a require 'bundler' to the Gemfile, there is no trace of the bundler making it to the vendor directory. So, my application fails with a

no such file to load -- bundler

Precisely at the point where load our dependencies.

require 'bundler'
Bundler.setup 

Is there something obvious I am missing here or can bundler not actually vendorize itself?

For what it's worth, I'm using jruby 1.7.8 and the application in question has the following Gemfile:

# run with --local to use locally cached gems
# bundle install --full-index --without testing development

# vendorized setup for production
# bundle install --full-index --without testing development --deployment


source 'https://rubygems.org'

gem 'bundler' 
gem 'sinatra'
gem 'sinatra-flash'
gem 'sinatra-contrib'
gem 'rack-parser', :require => 'rack/parser'
gem 'dynamic_attributes', :github => 'joona/dynamic_attributes', :require => false
gem 'httparty'
gem 'haml'
gem 'json'
gem 'airbrake'
# gem 'rake'

#gem 'omniauth-google' # TO-DO: deprecate
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'oauth'
gem 'oauth2'
gem 'omniauth'
gem 'omniauth-dropbox'
gem 'omniauth-facebook'
gem 'omniauth-google-oauth2'
gem 'omniauth-linkedin'
gem 'omniauth-twitter'
gem 'omniauth-windowslive', :git => 'git://github.com/joona/omniauth-windowslive.git'

gem 'lumber'
gem "log4r-gelf"

gem "resque", :github => "resque/resque", :branch => '1-x-stable'
gem "resque-pool"

gem 'tux', :require => false

gem 'actionmailer'
gem 'actionpack', '4.0.1'
gem 'activesupport', '4.0.1', :require => false
gem 'activerecord', '4.0.1'

platforms :jruby do
  gem 'activerecord-jdbc-adapter' #, :github => 'jruby/activerecord-jdbc-adapter'
  gem 'jdbc-mysql'
  gem 'activerecord-jdbcmysql-adapter'
end

platforms :ruby do
  gem 'mysql2'
end

group :testing do
  gem 'shoulda-matchers', :require => false
  gem 'webmock', '1.8.0', :require => false
  gem 'database_cleaner', '1.0.1'
  gem "sequel", "~> 4.3.0", :require => false
  gem 'rspec'
  gem 'capybara'
  #gem 'vcr'
  gem 'simplecov', :require => false
  gem 'launchy'
  gem 'rack-test', :require => false
  gem 'faker'
  gem 'fabrication'
  gem 'sinatra-sessionography', :require => false
  platforms :ruby do
    gem 'sqlite3'
  end
  platforms :jruby do
    gem 'jdbc-sqlite3'
  end
end
# 
group :development do
  gem 'guard', "1.8.3", :require => false
  gem 'guard-sass', '1.3.2', :require => false
  gem 'guard-less', '0.1.2', :require => false
  gem 'guard-process', '1.0.6', :require => false
  gem 'guard-rspec', '3.1.0', :require => false
  gem 'juicer'
  gem 'foreman', :require => false
  # shotgun with logging quickfix!
  #gem 'shotgun', :github => 'joona/shotgun'
  gem 'guard-shotgun', :git => 'https://github.com/rchampourlier/guard-shotgun.git'

  gem 'capistrano', '~> 2'
  gem 'rvm-capistrano'
end

group :production do
  platforms :ruby do
    gem 'passenger'
  end
  platforms :jruby do
    gem 'fishwife'
  end
end
5
  • Did you try using gem 'bundler' (at depencencies load time, in addition to Gemfile)?
    – mdesantis
    Nov 25, 2013 at 16:12
  • yes, it fails on require 'bundler' with a file not found. Bundler is indeed nowhere to be found in the vendor directory. Nov 25, 2013 at 16:14
  • It's dirty, but since you have the vendor folder you can try to require ./vendor/bundle/#{RUBY_ENGINE}/#{RUBY_VERSION}/gems/bundler-#{BUNDLER_VERSION}/lib/bundler.rb
    – mdesantis
    Nov 25, 2013 at 16:27
  • the problem is that it is not actually there even though I required the gem Nov 26, 2013 at 15:13
  • In the end I decided against --standalone as it basically generates code and creates alternate codepaths. Basically, I'm now packaging bundler and gem along with my custom ruby build. This gets the job done and it allows my vendorized rpm to call Bundler.setup, which seems to be the only way to use vendorized github dependencies in a production setting (this was the reason I needed bundler available to begin with). Jan 17, 2014 at 16:24

1 Answer 1

4

The reason this doesn't work is because Bundler.setup is the code that actually sets up your load path to find the vendored gems. If Bundler were vendored, it wouldn't be able to find it to do that setup.

You can do one of two things:

  1. Install Bundler as a system gem. This is the most common solution. You could build a separate RPM to install it (or maybe there's already one out there you can use) and depend on it in your app's RPM.

  2. Use Bundler's standalone mode. This will give you an application that does not depend on Bundler at all. In that case, you should remove the require 'bundler' and Bundler.setup lines from your application and instead add require_relative 'bundle/bundler/setup' (with the path adjusted if you're calling it from a file located somewhere other than the root directory of your project).

2
  • If I would set my buildpath correctly, I should be able to do a require bundle and then be able to run Bundler.setup, even if the gem lived in the vendor directory, right? Nov 26, 2013 at 14:17
  • I don't think there's any benefit to doing that over using bundle install --standalone.
    – Tim Moore
    Nov 27, 2013 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.