QA@IT

Capistrano でデプロイするとき PostgreSQL 環境変数依頼について

3401 PV

OS:CentOS 5.7
DB:PostgreSQL8.4

Capistrano でデプロイするとき、いつも必須な gem をインストールそうです。
サーバーで単純に PostgreSQL の gem ファイルをインストールすれば、これで大丈夫です:

gem install pg -- --with-pg-config=/usr/local/pgsql/bin/pg_config

しかし、ロカールマシンで「cap deploy」を実行するとき、下記のエラーメッセージが出ました:

 executing command
 ** [out :: SERVER_IP_ADDR] Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
 ** [out :: SERVER_IP_ADDR] 
 ** [out :: SERVER_IP_ADDR] /usr/local/rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
 ** [out :: SERVER_IP_ADDR] checking for pg_config... no
 ** [out :: SERVER_IP_ADDR] No pg_config... trying anyway. If building fails, please try again with
 ** [out :: SERVER_IP_ADDR] --with-pg-config=/path/to/pg_config
 ** [out :: SERVER_IP_ADDR] checking for libpq-fe.h... no
 ** [out :: SERVER_IP_ADDR] Can't find the 'libpq-fe.h header
 ** [out :: SERVER_IP_ADDR] *** extconf.rb failed ***
 ** [out :: SERVER_IP_ADDR] Could not create Makefile due to some reason, probably lack of
 ** [out :: SERVER_IP_ADDR] necessary libraries and/or headers.  Check the mkmf.log file for more
 ** [out :: SERVER_IP_ADDR] details.  You may need configuration options.
 ** [out :: SERVER_IP_ADDR] 
 ** [out :: SERVER_IP_ADDR] Provided configuration options:
 ** [out :: SERVER_IP_ADDR] --with-opt-dir
 ** [out :: SERVER_IP_ADDR] --without-opt-dir
 ** [out :: SERVER_IP_ADDR] --with-opt-include
 ** [out :: SERVER_IP_ADDR] --without-opt-include=${opt-dir}/include
 ** [out :: SERVER_IP_ADDR] --with-opt-lib
 ** [out :: SERVER_IP_ADDR] --without-opt-lib=${opt-dir}/lib
 ** [out :: SERVER_IP_ADDR] --with-make-prog
 ** [out :: SERVER_IP_ADDR] --without-make-prog
 ** [out :: SERVER_IP_ADDR] --srcdir=.
 ** [out :: SERVER_IP_ADDR] --curdir
 ** [out :: SERVER_IP_ADDR] --ruby=/usr/local/rvm/rubies/ruby-1.9.3-p0/bin/ruby
 ** [out :: SERVER_IP_ADDR] --with-pg
 ** [out :: SERVER_IP_ADDR] --without-pg
 ** [out :: SERVER_IP_ADDR] --with-pg-dir
 ** [out :: SERVER_IP_ADDR] --without-pg-dir
 ** [out :: SERVER_IP_ADDR] --with-pg-include
 ** [out :: SERVER_IP_ADDR] --without-pg-include=${pg-dir}/include
 ** [out :: SERVER_IP_ADDR] --with-pg-lib
 ** [out :: SERVER_IP_ADDR] --without-pg-lib=${pg-dir}/lib
 ** [out :: SERVER_IP_ADDR] --with-pg-config
 ** [out :: SERVER_IP_ADDR] --without-pg-config
 ** [out :: SERVER_IP_ADDR] --with-pg_config
 ** [out :: SERVER_IP_ADDR] --without-pg_config
 ** [out :: SERVER_IP_ADDR] 
 ** [out :: SERVER_IP_ADDR] 
 ** [out :: SERVER_IP_ADDR] Gem files will remain installed in /var/rails/afi/shared/bundle/ruby/1.9.1/gems/pg-0.14.0 for inspection.
 ** [out :: SERVER_IP_ADDR] Results logged to /var/rails/afi/shared/bundle/ruby/1.9.1/gems/pg-0.14.0/ext/gem_make.out
 ** [out :: SERVER_IP_ADDR] An error occured while installing pg (0.14.0), and Bundler cannot continue.
 ** [out :: SERVER_IP_ADDR] Make sure that `gem install pg -v '0.14.0'` succeeds before bundling.
    command finished in 27074ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /var/rails/afi/releases/20120717013720; true"
    servers: ["SERVER_IP_ADDR"]
    [SERVER_IP_ADDR] executing command
    command finished in 410ms
failed: "sh -c 'cd /var/rails/afi/releases/20120717013720 && bundle install --gemfile /var/rails/afi/releases/20120717013720/Gemfile --path /var/rails/afi/shared/bundle --deployment --quiet --without development test'" on SERVER_IP_ADDR

--with-pg-config=/path/to/pg_config について、どこで指定すればいいですか?

回答

config/deploy.rb に

before "bundle:install", :roles => :app do
  opts = "--with-pg-config=/usr/local/pgsql/bin/pg_config"
  run "cd #{app_path} && #{bundle_cmd} config build.pg #{opts}"
end

を追加。

参考資料:
http://stackoverflow.com/a/5167856/513554

編集 履歴 (0)
ウォッチ

この質問への回答やコメントをメールでお知らせします。