Bundler, Capistrano and Gemfile

I just had a ton of fun trying to deploy a Rails 3 app to a server. The
server (Ubuntu Hardy…whatever version that is), had Rails 2.3.5 on it,
and Ruby 1.8.6. I tried manually updating the gems, and of course it
failed installing Rails 3 (required Ruby >= 1.8.7), so I decided to use
RVM to get Ruby 1.9.2 running.

RVM installed fine, then I installed Ruby 1.9.2, then the Rails gems (
had some readline issues trying to get into the Rails console). I added
Passenger (the server is running Apache, and was running a lower version
of Passenger - v.2 something). That all worked. I was able to use
capistrano to deploy my new version of my app.

(side note - rvm and it’s files were installed locally into my home
directory - I had to install passenger using the
passenger-install-apache2-module script WITHOUT using sudo, so it would
point to my rvm ruby… that all actually worked)

My issue now is dealing with the Gemfile on my local dev system and the
deployed version now on the server. My local Mac is using sqlite and the
production server is using MySql. The Ubuntu box had an issue installing
the sqlite gem, and since the Gemfile specifies it, I was stuck. I tried
using the note in the Gemfile about “groups” and did something like:

group :development do
gem ‘sqlite3-ruby’, :require => ‘sqlite3’
gem ‘mongrel’,‘1.2.0.pre2’
end
group :production do
gem ‘mysql’
end

but upon trying to run the app on the server, it got an error saying
sqlite3 wasn’t available. I logged into the server and tried using the
Bundle command to get it set up… but it still tried to install
sqlite…even if I set RAILS_ENV=production. The only thing I did that
seemed to work was to manually, on the server, in the 'current’ly
deployed app, do bundle install --without development

So… What’s the magic that I have to do with Capistrano and the Gemfile
to use the correct gems in production? I saw this morning a post about
adding a line to my deploy.rb file:

require ‘bundler/capistrano’

but… will that do it? Do I have to add something to my deploy.rb
script to make sure my gems… proper for my environment… are set up?

I was able to get my app running in production by manually editing the
Gemfile on the server to remove the sqlite lines. And if I have any
changes I need to make to the app… I’ve editing the files directly. I
would love to just do a cap deploy… but that will break! (Not to
mention, having the gem ‘mysql’ in the Gemfile on my dev system fails,
because I don’t have the mysql gem installed…) Nice catch-22 there!

Any info would be highly appreciated.

Thanks.

group :production do
gem ‘mysql’
end

I don’t really have an answer, but I can confirm that I’ve also been
frustrated by the “group” feature in the Gemfile. I found it easier to
get rid of the need for it. Can you set up your development machine to
use mysql? I got rid of mongrel in favor of WEBrick on my development
machine just for this reason, too.

Paul wrote in post #965976:

group :production do
gem ‘mysql’
end

I don’t really have an answer, but I can confirm that I’ve also been
frustrated by the “group” feature in the Gemfile. I found it easier to
get rid of the need for it. Can you set up your development machine to
use mysql? I got rid of mongrel in favor of WEBrick on my development
machine just for this reason, too.

Yeah, that is an option. I did just find this page - wish I found it
last night when I was googling this problem!

http://blog.josephholsten.com/2010/09/deploying-with-bundler-and-capistrano/

Seems including that require line in the deploy.rb file, will let you do
things like:

cap bundle:install

and it will ignore, by default, :development and :test groups. And by
including that, cap:deploy will do a ‘bundle install’ on your server -
which I found here:

http://gembundler.com/deploying.html

I may or may not make that change and see what happens… but it’s all
working and I don’t want to break it right now :wink:

Paul wrote in post #965976:

group :production do
gem ‘mysql’
end

I don’t really have an answer, but I can confirm that I’ve also been
frustrated by the “group” feature in the Gemfile. I found it easier to
get rid of the need for it. Can you set up your development machine to
use mysql?

There are other good reasons to do that, but the group feature should
be usable. After all, we often have testing gems that we don’t need in
production.

If the group feature doesn’t work as advertised, then that’s a bug in
Bundler, it seems to me, and it should be fixed, not kludged around.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]