laserlemon / figaro

Simple Rails app configuration
MIT License
3.77k stars 287 forks source link

Starting Rails app through `foreman` doesn't load ENV vars on `config/puma.rb` file #286

Open vfonic opened 2 years ago

vfonic commented 2 years ago

Hi!

I'm using foreman gem to start my Rails app like this: foreman start -f Procfile.dev

In Procfile.dev the line that starts Rails server looks like this: backend: bundle exec puma -C config/puma.rb

And config/puma.rb looks like this:

# frozen_string_literal: true

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 1)
threads threads_count, threads_count

preload_app!

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

If I add some puts in there:

# frozen_string_literal: true

puts ENV['WEB_CONCURRENCY']
puts ENV['RAILS_MAX_THREADS']
puts ENV['RAILS_ENV']
puts ENV['PORT']
puts ENV['RAILS_MIN_THREADS']

workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 1)
threads threads_count, threads_count

preload_app!

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

I can see that only ENV['PORT'] is set to 5000. All the other ENV vars are nil.

Any ideas what could be the issue here?

If I start Rails via rails s, the ENV vars are all set.

PS The ENV vars are set in the rest of the app, even when I start the app through foreman, it's only that in config/puma.rb the ENV vars are not set. 🤷‍♂️