Problems with Rails credentials being read.

I’m trying to move from Heroku to Fly.io but I seem to be stuck on something related to the rails credentials.

==> Release command detected: bundle exec rails db:migrate

--> This release will not be available until the release command succeeds.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting virtual machine
	 Preparing to run: `bundle exec rails db:migrate` as root
	 2022/08/29 10:37:54 listening on [fdaa:0:6c19:a7b:b9b7:e45d:dc0a:2]:22 (DNS: [fdaa::3]:53)
	 /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/application.rb:348:in `require_environment!'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/application.rb:511:in `block in run_tasks_blocks'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/sentry-ruby-5.4.1/lib/sentry/rake.rb:24:in `execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/command.rb:51:in `invoke'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands.rb:18:in `<main>'
	 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	 Caused by:
	 OpenSSL::Cipher::CipherError:
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:204:in `final'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:204:in `_decrypt'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/message_encryptor.rb:160:in `decrypt_and_verify'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/messages/rotator.rb:22:in `decrypt_and_verify'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/encrypted_file.rb:92:in `decrypt'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/encrypted_file.rb:54:in `read'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/encrypted_configuration.rb:21:in `read'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/encrypted_configuration.rb:33:in `config'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/encrypted_configuration.rb:48:in `options'
	 /app/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.3.1/lib/active_support/core_ext/module/delegation.rb:303:in `method_missing'
	 /app/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.3.1/lib/active_record/railtie.rb:342:in `block in <class:Railtie>'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:32:in `instance_exec'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:32:in `run'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:61:in `block in run_initializers'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/initializable.rb:60:in `run_initializers'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/application.rb:372:in `initialize!'
	 /app/config/environment.rb:5:in `<main>'
	 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	 /app/vendor/bundle/ruby/3.1.0/gems/zeitwerk-2.6.0/lib/zeitwerk/kernel.rb:35:in `require'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/application.rb:348:in `require_environment!'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/application.rb:511:in `block in run_tasks_blocks'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `block in execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:281:in `execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/sentry-ruby-5.4.1/lib/sentry/rake.rb:24:in `execute'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:243:in `block in invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:241:in `invoke_prerequisites'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:218:in `block in invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `synchronize'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:199:in `invoke_with_call_chain'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/task.rb:188:in `invoke'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:160:in `invoke_task'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block (2 levels) in top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `each'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:116:in `block in top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:125:in `run_with_threads'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:110:in `top_level'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/application.rb:186:in `standard_exception_handling'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/rake-13.0.6/lib/rake/rake_module.rb:59:in `with_application'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/command.rb:51:in `invoke'
	 /app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands.rb:18:in `<main>'
	 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	 /app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.13.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
	 Tasks: TOP => db:migrate => db:load_config => environment
	 (See full trace by running task with --trace)
	 Starting clean up.
Error release command failed, deployment aborted

I figure this must be an issue with the RAILS_MASTER_KEY which got set automatically by Fly.io. I tried unsettling the secret and setting it myself from the master.key and putting it in the TOML file I even tried passing it as a build argument (fly deploy --remote-only --build-arg RAILS_MASTER_KEY=$(cat config/master.key) ) but I cannot get passed this error. I have no problems opening the production credentials locally.

Any ideas about what I’m doing wrong? Or maybe it has nothing to do with the master key?

Thanks

Never mind, as soon as I wrote down my question here I figured it out.

But it’s probably useful to someone else. It was the wrong key, Fly.io was grabbing the master.key however I noticed Heroku had a completely different key which helped me realize it was using the key stored in production.key. That key worked.

I’ve made a change to flyctl that should make the next release. It will check for the presence of a production.key first; and only if such a key is not found proceed on to pick up the master.key.

1 Like

That’s perfect. It’s great that it does this automatically. Thanks!