如何将 RAILS_MASTER_KEY 设置为生产服务器?
我正在使用 Capistrano 部署(到 nginx/乘客)一个 rails 6 应用程序(ruby 2.7.0)。为了让生产应用程序访问凭证,我试图向它提供 master.key
我可以获取到服务器的共享/配置文件夹的本地 env(开发)主 key 的 key 。尽管如此,部署应用程序最终还是失败了。
到那里 :
我从 Capistrano deploy 命令得到以下响应:
ActiveSupport::EncryptedFile::MissingKeyError: Missing encryption key to decrypt file with. Ask your team for your master key and write it to /home/deploy/tribe/releases/20200130135612/config/credentials/production.key or put it in the ENV['RAILS_MASTER_KEY'].
假设这可能是时间问题,我还使用相同的 key 更新 current/config 文件夹并收到相同的响应。
显然我没有得到它应该得到的主 key 。
Capistrano 链接文件任务如下
append :linked_files, "config/master.key"
set :linked_files, %w{config/master.key}
namespace :deploy do
namespace :check do
before :linked_files, :set_master_key do
on roles(:app), in: :sequence, wait: 10 do
unless test("[ -f #{shared_path}/config/master.key ]")
upload! 'config/master.key', "#{shared_path}/config/master.key"
end
end
end
end
end
最佳答案
我所做的是我不仅添加了链接 master.key 还添加了 production.key 因为日志提示的是 production.key,而不是 master
这是在我的 deploy.rb 中添加的
set :linked_files, %w{config/credentials/production.key}
现在 capistrano 可以工作并且没有 secret 问题
关于ruby-on-rails - 在生产环境中使用 Capistrano 的 Rails 多环境凭证 : How to set it up?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59988177/