Mastodon

Heroku Gotcha

今天把新 project 推上 heroku ,發現如下錯誤:

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
       Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
       Installing rails3_disable_x_sendfile... done
-----> Configure Rails to log to stdout
       Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
       Unresolved dependencies detected; Installing...
       Using --without development:test
       You have modified your Gemfile in development but did not check
       the resulting snapshot (Gemfile.lock) into version control

       You have added to the Gemfile:
       * therubyracer (>= 0.9.8)
       * libnotify
       * rb-inotify

       You have deleted from the Gemfile:
       * growl
       * rb-fsevent
       FAILED: http://devcenter.heroku.com/articles/bundler
 !     Heroku push rejected, failed to install gems via Bundler

當然我有一個已更新的 Gemfile.lock 了。看看訊息中的 gems ,再看回 Gemfile 中相關的設定:

group :development do
  gem "guard", ">= 0.6.2"
  case HOST_OS
    when /darwin/i
      gem 'rb-fsevent'
      gem 'growl'
    when /linux/i
      gem 'libnotify'
      gem 'rb-inotify'
    when /mswin|windows/i
      gem 'rb-fchange'
      gem 'win32console'
      gem 'rb-notifu'
  end

  gem "guard-bundler", ">= 0.1.3"
  gem "guard-rails", ">= 0.0.3"
  gem "guard-livereload", ">= 0.3.0"
  gem "guard-rspec", ">= 0.4.3"
  gem "rails-footnotes", ">= 3.7"
end

已經猜到是因為 heroku 自動查證 gemfile 時沒有考慮到 case 裡面的 OS。再搜尋 SO 可以看到類似的症狀。

解決方法?開一個新 branch ,在裡面把 Gemfile 修正,移除 heroku if/case 相關的 gem,再上傳這個 branch 做 heroku master即可。