Rails.application.credentials not allowing Rails application to deploy

I am trying to implement Stripe to my deployed Rails application. I use config/credentials.yml.enc to store the public and secret keys which works in the development environment. However, when I try to deploy the app to fly.io production the credentials file seems to be empty as it no longer provides access to my secret keys and throws this error:

>  => ERROR [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile                                                                                                     1.0s
> ------
>  > [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
> #0 0.976 bin/rails aborted!
> #0 0.976 NoMethodError: undefined method `[]' for nil:NilClass (NoMethodError)
> #0 0.976 
> #0 0.976 Stripe.api_key = Rails.application.credentials[:stripe][:secret]
> #0 0.976                                                        ^^^^^^^^^
> #0 0.976 /rails/config/initializers/stripe.rb:1:in `<main>'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/engine.rb:683:in `load'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/engine.rb:683:in `block in load_config_initializer'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.2/lib/active_support/notifications.rb:208:in `instrument'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/engine.rb:682:in `load_config_initializer'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/engine.rb:636:in `block (2 levels) in <class:Engine>'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/engine.rb:635:in `each'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/engine.rb:635:in `block in <class:Engine>'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/initializable.rb:32:in `instance_exec'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/initializable.rb:32:in `run'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/initializable.rb:61:in `block in run_initializers'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/initializable.rb:50:in `each'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/initializable.rb:50:in `tsort_each_child'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/initializable.rb:60:in `run_initializers'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/application.rb:423:in `initialize!'
> #0 0.976 /rails/config/environment.rb:5:in `<main>'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/application.rb:399:in `require_environment!'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/application.rb:585:in `block in run_tasks_blocks'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/sprockets-rails-3.4.2/lib/sprockets/rails/task.rb:61:in `block (2 levels) in define'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:243:in `block in invoke_prerequisites'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `each'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:241:in `invoke_prerequisites'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:27:in `block (2 levels) in perform'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:27:in `block in perform'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:44:in `block in with_rake'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:41:in `with_rake'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands/rake/rake_command.rb:20:in `perform'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:156:in `invoke_rake'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:73:in `block in invoke'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:149:in `with_argv'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:69:in `invoke'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/railties-7.1.2/lib/rails/commands.rb:18:in `<main>'
> #0 0.976 /rails/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
> #0 0.976 Tasks: TOP => environment
> #0 0.976 (See full trace by running task with --trace)
> ------
> Error: failed to fetch an image or build from source: error building: failed to solve: executor failed running [/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile]: exit code: 1

I assume it may have something to do with the secrets that I can edit for my virtual machine on the fly.io dashboard (i.e., maybe the master key needs to be added), but I’m lost as to what to do.

If anyone has any idea what could be causing this error that would be greatly appreciated. Thank you.

This may help:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.