Quantcast
Channel: Planet PostgreSQL
Viewing all articles
Browse latest Browse all 9948

Tom Copeland: Rails 3, bundler, and the pg gem

$
0
0

I was moving a Rails 2 app up to Rails 3 and, because I have PostgreSQL installed in a non-standard location on my server, I ran into problems when bundler was trying to install the pg gem. After fiddling about for a bit I ended up with this in my config/deploy.rb:

require 'bundler/capistrano'

task :set_config_for_pg_gem, :roles => [:app, :db] do
  run "cd #{current_path} && bundle config build.pg --with-pg-config=/usr/local/pgsql/bin/pg_config --no-rdoc --no-ri"
end

before "bundle:install", :set_config_for_pg_gem

This sets up the appropriate command line flags for the pg gem so that they're in place when Capistrano runs the bundle:install task. The --no-rdoc --no-ri part isn't necessary, but I figured it'll save a second or two. Note that these flags end up in the deploy user's home directory on the server:

$ cat ~/.bundle/config 
--- 
BUNDLE_BUILD__PG: --with-pg-config=/usr/local/pgsql/bin/pg_config --no-rdoc --no-ri

Running this task every time you deploy is a little wasteful since it sets the configuration unnecessarily - really you just need it before the first time you deploy. So you could optimize things by touching a file in shared/system/ or some such and checking it as part of this task.


Viewing all articles
Browse latest Browse all 9948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>