Skip to content

Instantly share code, notes, and snippets.

@conorh
Created January 30, 2010 16:11
Show Gist options
  • Save conorh/290606 to your computer and use it in GitHub Desktop.
Save conorh/290606 to your computer and use it in GitHub Desktop.
Migrate Rails project from config.gem to Bundler
Steps to migrate a Rails 2.3 project to bundler.
1. Install bundler
gem install bundler
2. Remove existing vendor gems directory
rm -rf vendor/gems
3. Remove all config.gem commands from config/environment.rb
4. Create Gemfile in RAILS_ROOT. Example:
# disable_system_gems uses the rubygems library, but prevents system gems
# from being loaded; only gems that are bundled will be available to your
# application. This option guarantees that dependencies of your
# application will be available to a remote system.
disable_system_gems
bundle_path "vendor/bundler_gems"
clear_sources
source "http://gemcutter.org"
gem "rails", "2.3.5"
gem "RedCloth"
gem "mysql"
gem "paperclip"
gem "will_paginate"
only :test do
gem "rspec"
gem "rspec-rails"
end
5. Create a config/preinitializer.rb
# Required for bundler
bundler_env = File.expand_path("#{File.dirname(__FILE__)}/../vendor/bundler_gems/environment.rb")
if File.exists?(bundler_env)
require bundler_env
else
puts "*** Gems not Bundled *** "
puts "You must first install Bundler, gem install bundler, and then bundle gems for this project"
puts "From rails root - gem bundle, or for OSX 10.6, ARCHFLAGS=\"-arch x86_64\" gem bundle"
exit(1)
end
6. Add Bundler.require_env to the bottom of each config/environments/* file
7. Bundle gems
gem bundle
or on OSX 10.6 (archflags required for MySQL)
ARCHFLAGS=\"-arch x86_64\" gem bundle
8. Add lines to .gitignore that ignores bundled gems directory, but keep gem cache:
# Used for bundler, only keep the cached directory
bin/*
vendor/bundler_gems/*
!vendor/bundler_gems/ruby/1.8/cache/
9. Add capistrano deploy tasks
namespace :bundler do
task :install do
run("gem install bundler --source=http://gemcutter.org")
end
task :symlink_vendor, :roles => :app, :except => { :no_release => true } do
shared_gems = File.join(shared_path, 'vendor/gems/ruby/1.8')
release_gems = "#{release_path}/vendor/gems/ruby/1.8"
# if you don't commit your cache, add cache to this list
%w(gems specifications).each do |sub_dir|
shared_sub_dir = File.join(shared_gems, sub_dir)
run("mkdir -p #{shared_sub_dir} && mkdir -p #{release_gems} && ln -s #{shared_sub_dir} #{release_gems}/#{sub_dir}")
end
end
task :bundle_new_release, :roles => :app, :except => { :no_release => true } do
bundler.symlink_vendor
# if you don't commit your cache, remove --cached from this line
run("cd #{release_path} && gem bundle --only #{rails_env} --cached")
end
end
# hook into capistrano's deploy task
after 'deploy:update_code', 'bundler:bundle_new_release'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment