werckerでnokogiriのインストールに失敗した時の対応

werckerを使って、ブランチをpushした時にrspecのテストを回すような仕組みを作ってた時に、wercker上でエラーになった時の対応です。

こんな感じのエラーが出ました。

Installing tzinfo 1.2.2
Installing nokogiri 1.6.7.2 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
.
.
.
.
.
No such file or directory - getcwd

Gem files will remain installed in /pipeline/cache/bundle-install/ruby/2.3.0/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /pipeline/cache/bundle-install/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/nokogiri-1.6.7.2/gem_make.out
Installing net-scp 1.2.1
Installing url_mount 0.2.1
Installing rack-protection 1.5.3
Installing rack-test 0.6.3
Installing treetop 1.4.15
Installing rspec-core 3.4.4
Installing rspec-expectations 3.4.0
Installing rspec-mocks 3.4.1
Installing activesupport 4.2.6
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.
failed: bundle install command failed

対応としては、bundle installでnokogiriのインストールがコケた時と同じように、–user-system-librariesオプションをつけてあげるだけです。

wercker.ymlのbundle-installの前に対応を入れてあげます。

build:
  # Steps make up the actions in your pipeline
  # Read more about steps on our dev center:
  # http://devcenter.wercker.com/docs/steps/index.html

  steps:
    - script:
      name: bundle - nokogiri use sys lib
      code: bundle config build.nokogiri --use-system-libraries
    - bundle-install
    - script:
      name: rspec
      code: bundle exec rspec spec/

これだけでOK!