Rails 7.0.4
使用 MRSK 部署时,我遇到了这个错误
[linux/arm64 build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile: #23 1.053 rails aborted! #23 1.053 ArgumentError: Missing
secret_key_base
for 'production' environment, set this string withbin/rails credentials:edit
#23 1.053 /rails/config/environment.rb:5:in `' #23 1.053 Tasks: TOP => environment #23 1.053 (See full trace by running task with --trace)
我的 Dockerfile 中卡住的那一行是
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
如果我运行
EDITOR=emacs bin/rails credentials:edit
,我可以看到在加密凭据文件中已经设置了secret_base_key
。在我的production.rb文件中,这一行被注释掉了:
# config.require_master_key = true
如果我取消上面那一行的注释,错误会改变为:
> [linux/arm64 build 10/10] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile:
#22 0.999 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'].
但这两个已经是真实的了 - 在config/master.key
中已经有一个文件(不在Git中),并且已经有一个RAILS_MASTER_KEY的环境变量。
此外,我的config/deploy.yml文件包含:
# Configure builder setup.
builder:
args:
RUBY_VERSION: "<%= Pathname.pwd.join('.ruby-version').read.strip.delete_prefix('ruby-') %>"
BUNDLER_VERSION: "<%= Bundler::LockfileParser.new(Pathname.pwd.join('Gemfile.lock').read).bundler_version %>"
RAILS_MASTER_KEY: "<%= ENV['RAILS_MASTER_KEY'] %>"
RAILS_MASTER_KEY
不是一个好主意。 - Pavel KalashnikovRUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
而无需注入主密钥以供在docker构建中使用。 - Michael