ruby-on-rails - 在生产环境中使用 Capistrano 的 Rails 多环境凭证 : How to set it up?

标签 ruby-on-rails capistrano credentials

如何将 RAILS_MASTER_KEY 设置为生产服务器?

我正在使用 Capistrano 部署(到 nginx/乘客)一个 rails 6 应用程序(ruby 2.7.0)。为了让生产应用程序访问凭证,我试图向它提供 master.key
我可以获取到服务器的共享/配置文件夹的本地 env(开发)主 key 的 key 。尽管如此,部署应用程序最终还是失败了。

到那里 :

  • step 1 在本地环境中,我为生产环境生成一个master key,并添加相关变量。我也尝试过使用主 key 。
  • 步骤 2 我手动将该 key 添加到服务器 shared/config/master.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/

    相关文章:

    ruby-on-rails - Capistrano 部署到暂存和生产

    ruby-on-rails - 非特权、非 root 用户启动或重启 webserver 服务器,例如没有 root 或 sudo 的 nginx

    PowerShell IIS Set-WebConfigurationProperty - 锁定 ApplicationHost.config 部分

    security - 每个存储桶的 Amazon S3 安全凭证

    ruby-on-rails - AWS Rails Capistrano PG 部署错误

    git - Jenkins 的 npm install 无法安装托管在 bitbucket 上的模块

    javascript - 用于标记为完成的按钮,然后添加到已完成的列表

    mysql - .find( :all ) with specific conditions return in Ruby on Rails? 是什么

    ruby-on-rails - Gem libxml-ruby (1.1.4) 安装但在运行时失败

    javascript - 更改单选按钮输入选择未按预期工作,无法弄清楚