Rails: Moving `master.key` to production server
Asked Answered
C

2

1

I am trying to deploy an updated version of a rails app to a droplet on DigitalOcean using mina

When I run mina deploy I get the error Missing encryption key to decrypt file with. Ask your team for your master key and write it to /home/my_rails_project/app/tmp/build-153920174210305/config/master.key or put it in the ENV['RAILS_MASTER_KEY'].

I was expecting this error as I haven't yet worked out how to add the details to the server.

A number of articles suggest there are two means of doing this:

Option 1: Place the config/master.key file in the server. You’ll normally want to symlink this file to a shared folder in the server filesystem. Again, do not version your config/master.key file.

Option 2: create a RAILS_MASTER_KEY ENV variable. Rails will detect it and use it as your master key, e.g. in heroku: heroku config:set RAILS_MASTER_KEY= < your-master-key-here >.

I have tried option 1 using FileZilla, however, I am unable to access the folder which is where the article suggests the file should be stored /home/deploy/my-rails-project/shared/config/master.key -> Error: Directory /home/my-rails-project/app/shared/config: permission denied. I am also unable to see the master.key file on my local computer through FileZilla. Similarly, if I use the console on Digital Ocean I get the permission denied error

Please could you advise me how to move master.key to the production server

Thanks in advance for your help

Chiasmus answered 10/10, 2018 at 21:28 Comment(1)
did you try option 2? It's add this line export RAILS_MASTER_KEY="xxx" on .bashrcLief
C
4

I ended up working out how to do option 2, as suggested by @edudepetris. This involved adding the line RAILS_MASTER_KEY=<my_master.key> to the top of my .bashrc - this was done by typing nano .bashrc when logged into the server

Chiasmus answered 14/10, 2018 at 14:46 Comment(0)
B
0

You could use the capistrano-linked-files Gem (https://github.com/runar/capistrano-linked-files). This gem provides Capistrano 3.1 reciepes to upload your linked files and directories. Linked files and directories are placed in the shared directory on your remote servers and kept between deployments.

Add the gem to your Gemfile:

gem 'capistrano-linked-files'

Then add the Gem to your Capfile:

require 'capistrano/linked_files'

Now add the master.key to your in deploy.rb:

set :linked_files, 'config/master.key'

Now you can upload the master key via:

$ bundle exec cap <STAGE> linked_files:upload

All these details are from the README.md from https://github.com/runar/capistrano-linked-files. Have a look!

Alternative solution

The capistrano/rails Gem (https://github.com/capistrano/rails) has a section about this topic, too.

Brash answered 23/9, 2019 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.