Rails 7.1 – Missing `secret_key_base` for ‘production’ environment when deploying to production via Dokku

  Kiến thức lập trình

I have a Rails 7.1.3.2 app and I am using Dokku to deploy it to the server.

In the process of the deployment, I get this error:

remote: ------
remote: Dockerfile:37
remote: --------------------
remote:   35 |
remote:   36 |     # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
remote:   37 | >>> RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
remote:   38 |     #RUN if [[ "$RAILS_ENV" == "production" ]]; then 
remote:   39 |     #      mv config/credentials.yml.enc config/credentials.yml.enc.backup; 

I found this/similar issue reported on github, and after adding this recommendation, the error above disappeared, but a similar one popped up:

=====> Start of redata-prod container output (web.1)
       bin/rails aborted!
       ArgumentError: Missing `secret_key_base` for 'production' environment, set this string with `bin/rails credentials:edit` (ArgumentError)
               raise ArgumentError, "Missing `secret_key_base` for '#{Rails.env}' environment, set this string with `bin/rails credentials:edit`"
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       /rails/config/environment.rb:5:in `<main>'
       Tasks: TOP => db:prepare => db:load_config => environment
       (See full trace by running task with --trace)

I am not sure how to deal with the production secret_key_base keys. How do I resolve this error?

Any advice will be appreciated.

LEAVE A COMMENT