Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Master Key in Gitlab.com CI

I am trying to set up gitlab.com continuous integration(CI) for one of my private projects. But rails db:migrate is failing with the following error:

ActiveSupport::EncryptedFile::MissingKeyError: Missing encryption key to decrypt file with. Ask your team for your master key and write it to /builds/shubh-muhurat/Backend/config/master.key or put it in the ENV['RAILS_MASTER_KEY']

The master key should not be there in the repository, but if I set RAILS_MASTER_KEY using .gitlab-ci.yml I have to commit the master key to the repository.

So is there a better way of putting the master key.

PS: I am using gitlab.com CI.

Version: Rails 5.2.0.beta2

like image 974
Vivek Tiwary Avatar asked Sep 04 '26 06:09

Vivek Tiwary


2 Answers

I solved this by adding the master key to the projects secret variables and then injecting it during the before_script phase:

- echo "$MASTER_KEY" > config/master.key

like image 58
Pedro Coutinho Avatar answered Sep 07 '26 00:09

Pedro Coutinho


After doing a bit of research for finding the easiest way of declaring the variables, I came across the Variables section in GitLab. The Variables section is located under the repository CI/CD setting. There is also an option of making your variables protected.

like image 40
Vivek Tiwary Avatar answered Sep 06 '26 22:09

Vivek Tiwary