LoginSignup
4
5

More than 5 years have passed since last update.

Heroku で Capybara - Poltergeist を使う時に注意すること

Last updated at Posted at 2015-12-17

ブログを更新しました。元の記事はコチラ


Heroku で Capybara と Poltergeist を使う時につまずいたのでメモ。

原因は PhantomJS がないから。
ローカルではインストールして動いているけど、はて、herokuではどうするのかなと。
何もしないと下のようなエラーが出ます。

Cliver::Dependency::NotFound: Could not find an executable ["phantomjs"] on your path.

実装

まずはこのコマンド。

$ heroku buildpack:set https://github.com/ddollar/heroku-buildpack-multi.git

  
ルートに .buildpacks を作ろう。

$ touch .buildpacks

  
その中身はこう。
.buildpacks

https://github.com/heroku/heroku-buildpack-ruby
https://github.com/stomita/heroku-buildpack-phantomjs

  
herokuに環境変数を追加。
コメントで教えてもらいました。今はいらないらしい。
Ruby - Herokuのapp作成手順(buildpack-multiを使う場合も含む) - Qiita

$ heroku config:set PATH="/usr/local/bin:/usr/bin:/bin:/app/vendor/phantomjs/bin"
$ heroku config:set LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib:/app/vendor/phantomjs/lib

  
これで完了かなと思ってたら、Procfileがいるようで。
せっかくなので WEBrick 使ってたけど Puma にしました。

  
Gemfile

group :production do
  gem 'puma'
end

  
Procfile (ルートに設置)

web: bundle exec puma -C config/puma.rb

  
config/puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['MAX_THREADS'] || 5)
threads threads_count, threads_count

preload_app!

rackup      DefaultRackup
port        ENV['PORT']     || 3000
environment ENV['RACK_ENV'] || 'development'

on_worker_boot do
  # Worker specific setup for Rails 4.1+
  # See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
  ActiveRecord::Base.establish_connection
end

  
でOK!と思ってたら、まだだめ。
なぜかHerokuでエラー。ログはこんな感じ。

at=error code=H14 desc="No web processes running"

Dynoが一つも稼働してない模様。
試しにこうやって 0 Dyno増やしてみた。

$ heroku ps:scale web+0
Scaling dynos... done, now running web at 0:Free.

やっぱり 0 やん。
heroku ps:scale web+1 で良いのかなと思ったけど
念のため Heroku のダッシュボードでも確認して、そちらで起動しました。

以上!

参考

Heroku, Ruby on Rails and PhantomJS

Add explanation on README.md, that just setting buildpack on config is not enough · Issue #51 · ddollar/heroku-buildpack-multi

Deploying Rails Applications with the Puma Web Server | Heroku Dev Center

Buildpacks | Heroku Dev Center

node.js - Heroku Error H14 (No web processes running) - Stack Overflow

  

http://workabroad.jp/posts/2170

4
5
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5