Search code examples
ruby-on-railsbundlepuma

Rails on development mode without Puma


After I have installed Puma for production mode, it should not run on my local machine, however Puma is starting on development mode and stops after a moment with no errors.

$ rails server
=> Booting Puma
=> Rails 4.2.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[8707] Puma starting in cluster mode...
[8707] * Version 3.1.0 (ruby 2.3.0-p0), codename: El Niño Winter Wonderland
[8707] * Min threads: 1, max threads: 6
[8707] * Environment: development
[8707] * Process workers: 1
[8707] * Phased restart available
[8707] * Listening on tcp://localhost:3000
[8707] Use Ctrl-C to stop

It looks like is a bundler issue: github.com/puma/puma/issues/983


Solution

  • It's not a real solution but a nice work around for people that using there server for production mode with Puma and want to work on local machine development mode with WEBrick. This solution base on mrvncaragay idea

    1. split you Gemfile to 3 files:

    Gemfile_base
    Gemfile_development
    Gemfile_production
    

    in Gemfile_base include all the gems that not test, development & production. There is not reason to include source 'https://rubygems.org' or in Gemfile_development or Gemfile_production file. in Gemfile_development include only test & development gems in Gemfile_production include only production gems

    2. Replace all the line in the Gemfile to:

    source 'https://rubygems.org'
    
    gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
    #gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
    gemfiles.each do |gemfile|
      instance_eval File.read(gemfile)
    end
    

    3. Deploy to production server

    4. Add Gemfile to .gitignore file

    #bundle Puma in development mode bad wordaround
    Gemfile
    

    5. Untrack Gemfile from source control

    git rm --cached Gemfile
    

    6. Change the commit line in of Gemfile in production server from:

    source 'https://rubygems.org'
    
    gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
    #gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
    gemfiles.each do |gemfile|
      instance_eval File.read(gemfile)
    end
    

    to:

    source 'https://rubygems.org'
    
    #gemfiles = [ 'Gemfile_base', 'Gemfile_development' ]
    gemfiles = [ 'Gemfile_base', 'Gemfile_production' ]
    gemfiles.each do |gemfile|
      instance_eval File.read(gemfile)
    end