Rails production.key issue

Hello,

When I was deploying my app with master.key and credentials.yml.enc, there was no problem. But I needed to use different API keys for the production environment so I created production.key and production.yml.enc with rails commands.

-I used this code fly secrets set RAILS_PRODUCTION_KEY=$(cat config/credentials/production.key).

  • I set the production key with fly secrets set method as well.

But still getting the error below when I do fly deploy.

Preparing to run: `bin/rails fly:release` as root
         Virtual machine started successfully
         2023/03/09 21:32:16 listening on [fdaa:0:ba11:a7b:bbfb:b123:709b:2]:22 (DNS: [fdaa::3]:53)
         2023/03/09 21:32:16 listening on [fdaa:0:ba11:a7b:bbfb:b123:709b:2]:22 (DNS: [fdaa::3]:53)
         2023/03/09 21:32:16 listening on [fdaa:0:ba11:a7b:bbfb:b123:709b:2]:22 (DNS: [fdaa::3]:53)
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:186:in `_decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_file.rb:104:in `decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_file.rb:66:in `read'
         /app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.2/lib/active_record/railtie.rb:332:in `block in <class:Railtie>'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `run'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:204:in `final'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
         /app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.2/lib/active_record/railtie.rb:332:in `block in <class:Railtie>'
         /app/config/environment.rb:7:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:48:in `options'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:511:in `block in run_tasks_blocks'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:204:in `_decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:21:in `read'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:60:in `run_initializers'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
         /app/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
         ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:186:in `_decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_file.rb:104:in `decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_file.rb:66:in `read'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:48:in `options'
         /app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.2/lib/active_record/railtie.rb:332:in `block in <class:Railtie>'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `run'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:511:in `block in run_tasks_blocks'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:204:in `final'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:204:in `_decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:21:in `read'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
         /app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.2/lib/active_record/railtie.rb:332:in `block in <class:Railtie>'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:60:in `run_initializers'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
         /app/config/environment.rb:7:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         Tasks: TOP => fly:release => db:migrate => db:load_config => environment
         (See full trace by running task with --trace)
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         Tasks: TOP => fly:release => db:migrate => db:load_config => environment
         (See full trace by running task with --trace)
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         Tasks: TOP => fly:release => db:migrate => db:load_config => environment
         (See full trace by running task with --trace)
         Starting clean up.
         Starting clean up.
         Starting clean up.
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         Caused by:
         OpenSSL::Cipher::CipherError:
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:204:in `final'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:204:in `_decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_file.rb:104:in `decrypt'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_file.rb:66:in `read'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:21:in `read'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:33:in `config'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/encrypted_configuration.rb:48:in `options'
         /app/vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.4.2/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
         /app/vendor/bundle/ruby/3.2.0/gems/activerecord-7.0.4.2/lib/active_record/railtie.rb:332:in `block in <class:Railtie>'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `instance_exec'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:32:in `run'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:61:in `block in run_initializers'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/initializable.rb:60:in `run_initializers'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:372:in `initialize!'
         /app/config/environment.rb:7:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:348:in `require_environment!'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/application.rb:511:in `block in run_tasks_blocks'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
         /app/vendor/bundle/ruby/3.2.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands/rake/rake_command.rb:18:in `perform'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/command.rb:51:in `invoke'
         /app/vendor/bundle/ruby/3.2.0/gems/railties-7.0.4.2/lib/rails/commands.rb:18:in `<main>'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         /app/vendor/bundle/ruby/3.2.0/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
         Tasks: TOP => fly:release => db:migrate => db:load_config => environment
         (See full trace by running task with --trace)
         Starting clean up.

Here is my Docker file:

# syntax = docker/dockerfile:experimental

# Dockerfile used to build a deployable image for a Rails application.
# Adjust as required.
#
# Common adjustments you may need to make over time:
#  * Modify version numbers for Ruby, Bundler, and other products.
#  * Add library packages needed at build time for your gems, node modules.
#  * Add deployment packages needed by your application
#  * Add (often fake) secrets needed to compile your assets

#######################################################################

# Learn more about the chosen Ruby stack, Fullstaq Ruby, here:
#   https://github.com/evilmartians/fullstaq-ruby-docker.
#
# We recommend using the highest patch level for better security and
# performance.

ARG RUBY_VERSION=3.2.0
ARG VARIANT=jemalloc-slim
FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-${VARIANT} as base

LABEL fly_launch_runtime="rails"

ARG BUNDLER_VERSION=2.3.26

ARG RAILS_ENV=production
ENV RAILS_ENV=${RAILS_ENV}

ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true

ARG BUNDLE_WITHOUT=development:test
ARG BUNDLE_PATH=vendor/bundle
ENV BUNDLE_PATH ${BUNDLE_PATH}
ENV BUNDLE_WITHOUT ${BUNDLE_WITHOUT}

RUN mkdir /app
WORKDIR /app
RUN mkdir -p tmp/pids

RUN gem update --system --no-document && \
    gem install -N bundler -v ${BUNDLER_VERSION}

#######################################################################

# install packages only needed at build time

FROM base as build_deps

ARG BUILD_PACKAGES="git build-essential libpq-dev wget vim curl gzip xz-utils libsqlite3-dev"
ENV BUILD_PACKAGES ${BUILD_PACKAGES}

RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y ${BUILD_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

#######################################################################

# install gems

FROM build_deps as gems

COPY Gemfile* ./
RUN bundle install && rm -rf vendor/bundle/ruby/*/cache

#######################################################################

# install deployment packages

FROM base

ARG DEPLOY_PACKAGES="postgresql-client file vim curl gzip libsqlite3-0"
ENV DEPLOY_PACKAGES=${DEPLOY_PACKAGES}

RUN --mount=type=cache,id=prod-apt-cache,sharing=locked,target=/var/cache/apt \
    --mount=type=cache,id=prod-apt-lib,sharing=locked,target=/var/lib/apt \
    apt-get update -qq && \
    apt-get install --no-install-recommends -y \
    ${DEPLOY_PACKAGES} \
    && rm -rf /var/lib/apt/lists /var/cache/apt/archives

# copy installed gems
COPY --from=gems /app /app
COPY --from=gems /usr/lib/fullstaq-ruby/versions /usr/lib/fullstaq-ruby/versions
COPY --from=gems /usr/local/bundle /usr/local/bundle

#######################################################################

# Deploy your application
COPY . .

# Adjust binstubs to run on Linux and set current working directory
RUN chmod +x /app/bin/* && \
    sed -i 's/ruby.exe\r*/ruby/' /app/bin/* && \
    sed -i 's/ruby\r*/ruby/' /app/bin/* && \
    sed -i '/^#!/aDir.chdir File.expand_path("..", __dir__)' /app/bin/*

# The following enable assets to precompile on the build server.  Adjust
# as necessary.  If no combination works for you, see:
# https://fly.io/docs/rails/getting-started/existing/#access-to-environment-variables-at-build-time
ENV SECRET_KEY_BASE 1
# ENV AWS_ACCESS_KEY_ID=1
# ENV AWS_SECRET_ACCESS_KEY=1

# Run build task defined in lib/tasks/fly.rake
ARG BUILD_COMMAND="bin/rails fly:build"
RUN ${BUILD_COMMAND}

# Default server start instructions.  Generally Overridden by fly.toml.
ENV PORT 8080
ARG SERVER_COMMAND="bin/rails fly:server"
ENV SERVER_COMMAND ${SERVER_COMMAND}
CMD ${SERVER_COMMAND}

What you want is:

fly secrets set RAILS_MASTER_KEY

In other words, use the same environment variable you used to use, just with a different value.

Hey rubys,

I have already set up RAILS_MASTER_KEY, no problem with that if you asking for that. It reads the keys in my credentials.yml.enc. But when I add my production keys with production.yml.enc, it is giving the error I shared. If I misunderstood I will kindly ask you to explain little more because I am junior and almost everything is new to me :slight_smile: I feel like I am missing something really basic. Thank you for your help in advance.

Here’s the code that flyctl launch uses to set the secret. It is in a language called go, which you may not know how to write, but the code is readable even if you don’t:

See also How to set RAILS_PRODUCTION_KEY config var on a Rails 6 app on Heroku - Stack Overflow, in particular:

Bottom line: an environment variable named RAILS_PRODUCTION_KEY (or any other Rails environment-flavored variable name) is not a thing–Rails doesn’t pay attention to it.

Oh, now I see. Everything is working as intended. Thank you so much rubys.

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