Search code examples
ruby-on-railsrubypumasecret-key

Missing 'secret_token' and 'secret_key_base' for 'production' environment (Puma)


I don't understand why my secret_token and secret_key_base aren't being read by Puma. The app is being deployed through Capistrano, Nginx and Puma.

secrets.yml

development:
  secret_key_base: XXXXXXXXXXXXXXXXXX
  secret_token: XXXXXXXXXXX

test:
  secret_key_base: XXXXXXXXXXXXXXXXXXXXXXXXXXXX

production:
  secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
  secret_token: <%= ENV["SECRET_TOKEN"] %>

My .gitignore file is not blocking my secrets.yml file, yet everytime I try to connect to my server I am told An unhandled lowlevel error occurred. The application logs may have details.

And my application log tells me that I am Missing 'secret_token' and 'secret_key_base' for 'production' environment

Full application log

=== puma startup: 2016-04-05 07:00:04 -0400 ===
2016-04-05 07:00:09 -0400: Rack app error: #<RuntimeError: Missing     `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml`>
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:534:in `validate_secret_key_config!'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:246:in `env_config'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/engine.rb:514:in `call'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/railties-4.2.6/lib/rails/application.rb:165:in `call'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/puma-3.2.0/lib/puma/configuration.rb:227:in `call'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/puma-3.2.0/lib/puma/server.rb:561:in `handle_request'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/puma-3.2.0/lib/puma/server.rb:406:in `process_client'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/puma-3.2.0/lib/puma/server.rb:271:in `block in run'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/puma-3.2.0/lib/puma/thread_pool.rb:111:in `call'
/home/deploy/apps/IASAS_site/shared/bundle/ruby/2.2.0/gems/puma-3.2.0/lib/puma/thread_pool.rb:111:in `block in spawn_thread'

Please help!


Solution

  • By looking at your configuration file the answer seems to be quite obvious.

    In production Puma takes these values from two environment variables (SECRET_KEY_BASE and SECRET_TOKEN). You need to define these environment variables on your production server.