Search code examples
ruby-on-railsrubyunicorncapistrano3

`build': /home/releases/#{release_number}/Gemfile not found (Bundler::GemfileNotFound)


INFO -- : executing ["/home/shared/bundle/ruby/2.1.0/bin/unicorn", "-c", "/home/current/config/unicorn/production.rb", "-E", "deployment", "-D", {12=>#<Kgio::UNIXServer:fd 12>}] (in /home/releases/20140714144301)
DEBUG[b59ba27c]     I, [2014-07-14T14:43:33.495683 #27897]  INFO -- : forked child re-executing...
DEBUG[b59ba27c]     /home/
DEBUG[b59ba27c]     lic/.rvm/gems/ruby-2.1.2@global/gems/bundler-1.6.3/lib/bundler/definition.rb:23:in `build': /home/releases/20140710032913/Gemfile not found (Bundler::GemfileNotFound)

I am pretty sure the problem stems from the fact that with zero-downtime deployment, unicorn is caching this release number: 20140710032913. I have capistrano set to keep 5 releases. After 5 deploys, the old release number is rolled off. How can I force unicorn to use the current Gemfile?

Possible duplicate: Unicorn restart issue with capistrano


Solution

  • In my #{Rails.root}/config/unicorn/#{environment}.rb file I needed:

    before_exec do |_server|
      ENV['BUNDLE_GEMFILE'] = "#{working_directory}/Gemfile"
    end