Search code examples
ruby-on-railsruby-on-rails-5

How can I move my Rails 5.2 master.key to the server using Mina deployment?


I would like to move my master.key file to the server (on Digital Ocean) using mina deploy.

Within deploy.rb i currently have

set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml', 'config/master.key')

# Put any custom commands you need to run at setup
# All paths in `shared_dirs` and `shared_paths` will be created on their own.
task :setup do

  in_path(fetch(:shared_path)) do

     command %[mkdir -p config]

     # Create database.yml for Postgres if it doesn't exist
     path_database_yml = "config/database.yml"
     database_yml = %[production:
     database: #{fetch(:user)}
     adapter: postgresql
     pool: 5
     timeout: 5000]
   command %[test -e #{path_database_yml} || echo "#{database_yml}" > #{path_database_yml}]

   # Create secrets.yml if it doesn't exist
   path_secrets_yml = "config/secrets.yml"
   secrets_yml = %[production:\n  secret_key_base:\n    #{`bundle exec rake secret`.strip}]
  command %[test -e #{path_secrets_yml} || echo "#{secrets_yml}" > #{path_secrets_yml}]

  # Remove others-permission for config directory
  command %[chmod -R o-rwx config]
  end
end

...

desc "Deploys the current version to the server."
    task :deploy do
      # uncomment this line to make sure you pushed your local branch to the remote origin
      # invoke :'git:ensure_pushed'
      deploy do
        # Put things that will set up an empty directory into a fully set-up
        # instance of your project.
        invoke :'git:clone'
        invoke :'deploy:link_shared_paths'
        invoke :'bundle:install'
        invoke :'rails:db_migrate'
        invoke :'rails:assets_precompile'
        invoke :'deploy:cleanup'

        on :launch do
          invoke :'whenever:update' # should update the cron file
          command "sudo service #{fetch(:user)} restart"
        end
      end

      # you can use `run :local` to run tasks on local machine before of after the deploy scripts
      # run(:local){ say 'done' }
    end

Please could you advise me what I need to add into the above in order to move the file config/master.key from my development machine to shared/config/master.key on the server


Solution

  • As I didn't get any response to this question, I ended up adding RAILS_MASTER_KEY=<my_master.key> to the top of my .bashrc file on the server via nano .bashrc.

    Articles I read suggested this should be added to the very top of the .bashrc file and this seems to be working successfully