Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to include bundler itself when using bundle install --deployment

Tags:

ruby

bundler

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
like image 353
Jilles van Gurp Avatar asked Nov 25 '13 15:11

Jilles van Gurp


People also ask

Where do I put bundler?

Install BundlerSelect Tools | Bundler | Install Bundler from the main menu. Press Ctrl twice and execute the gem install bundler command in the invoked popup. Open the RubyMine terminal emulator and execute the gem install bundler command.

What is the difference between bundle install and bundle update?

The most common question I've heard about Bundler is about the difference between bundle install and bundle update . In a nutshell: bundle install handles changes to the Gemfile and bundle update upgrades gems that are already managed by Bundler.

What is the difference between bundle and bundler?

The executables bundle & bundler have the same functionality and therefore can be used interchangeably. You can see in the bundler/exe directory that the bundler executable just loads the bundle executable. It seems to me that the bundle command is more commonly used than the bundler command.

What happens when you run bundle install?

When you make a change to the Gemfile(5) and then run bundle install , Bundler will update only the gems that you modified. In other words, if a gem that you did not modify worked before you called bundle install , it will continue to use the exact same versions of all dependencies as it used before the update.


1 Answers

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).

like image 145
Tim Moore Avatar answered Oct 17 '22 08:10

Tim Moore