About the relationship between Rails credentials.yml.enc and master.key (undefined method `[]'for nil: NilClass (NoMethodError))

When I created a public clone of a customer and revenue app created with Rails that I run at work, I was addicted to the title, so I will leave it as a memo.

Background

  1. Clone the source code locally from a private repository on GitHub
  2. After deleting the privacy information, delete the .git file and change the app name (folder name) to _v2
  3. git init and push to remote repository
  4. In cooperation with CircleCi, create an automatic test when merged with master
  5. I want to make RDS the db of the production environment, so I set the local credentials.yml to enter the RDS information (at this time, I used the credentials: edit command once, and for some reason I used the credential file once. I'm following the mysterious procedure of removing and recreating with the credeitials: edit command)
  6. I deployed a container to ECR and tried to perform an ECS task, but the ECR container is not started
  7. Since I was pushing the Dockerfile for development, I added the rails s command without starting it.
  8. Once I tried to check the operation in the development environment and docker build, an error occurred that the server did not start (undefined method` []' for nil: NilClass (NoMethodError))

This is the process.

AWS was a trial app once, and I had set up automatic deployment as a production environment, so I proceeded without understanding the service well.

What was the problem

The problem is usually the fifth item. Lol

If you take a closer look,

--credential.yml.enc is encrypted and decrypted using master.key --When git push, master.key is not pushed (because it is listed in .gitignore)

In other words, there was no master.key at the time of cloning. And master.key was created during the first credentials: edit command.

What's more, I deleted the credentials.yml file once and ran the credentials: edit command again, creating credentials.yml that was inconsistent with master.key.

As a result, it could not be encrypted or decrypted, and the RDS settings that had been created once had disappeared. Is it like that? Maybe

How it was solved

in this case,

--Once deleted master.key and credentials.yml --Recreate the two files with the credentials.edit command

I went through the process!

It seems to be a fairly common error, so I found a lot of information when I looked it up, but it was a good study. If you have a similar case, please go beyond my corpse! !!

Recommended Posts

About the relationship between Rails credentials.yml.enc and master.key (undefined method `[]'for nil: NilClass (NoMethodError))
[Rails / ActiveRecord] About the difference between create and create!
Rails error undefined method ʻimage_name'for nil: NilClass handling
[Rails] I learned about the difference between resources and resources
[Rails Tutorial] "NoMethodError (undefined method` activation_digest ='for # <User: 0x00000003156938>
About the relationship between HTTP methods, actions and CRUD
about the where method (rails)
[Ruby on Rails] undefined method ʻid'for nil: NilClass error resolution method
About the relationship between the Java String equality operator (==) and initialization. Beginners
[Rails] I studied the difference between new method, save method, build method and create method.
[Ruby on Rails] Follow function undefined method ʻid'for nil: NilClass error resolution
About the difference between irb and pry
A note about the Rails and Vue process
[Rails] Difference between create method and new + save method
Relationship between UI test and recording, implementation method
[Ruby] I thought about the difference between each_with_index and each.with_index
About the difference between classes and instances in Ruby
[Rails] What is the difference between redirect and render?
Verification of the relationship between Docker images and containers
[Rails] I investigated the difference between redirect_to and render.
[Swift] UITextField taught me the difference between nil and ""