Open4

SECRET_KEY_BASE_DUMMYが使えない(Rails 7.1.2)

trysmrtrysmr

Rails 7.1で追加され、rails newで生成されるDockerfileにもあるSECRET_KEY_BASE_DUMMY=1が使えない。production.rbでconfig.require_master_key = trueとなっているとdocker buildでエラーとなる。

 > [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 bin/rails assets:precompile:
0.712 Missing encryption key to decrypt file with. Ask your team for your master key and write it to /rails/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].
------
Dockerfile:37
--------------------
  35 |
  36 |     # Precompiling assets for production without requiring secret RAILS_MASTER_KEY
  37 | >>> RUN SECRET_KEY_BASE_DUMMY=1 bin/rails assets:precompile
  38 |
  39 |
--------------------
ERROR: failed to solve: process "/bin/sh -c SECRET_KEY_BASE_DUMMY=1 bin/rails assets:precompile" did not complete successfully: exit code: 1
trysmrtrysmr

これ、config/initializers内でcredentialsを読み込むような処理、例えばSSOの設定値とか、をしてたら結局RAILS_MASTER_KEY必要だから使い道が限られるな。