Do you need dotenv-rails?

I wondered if
dotenv-rails is needed while deploying the application currently being created with aws, so I posted it

・ What is dotenv-rails?

How to install gem (dotenv-rails) and .env that can manage environment variables that can be used in Rails

Simply put, you can set your own variables and use them in many places. I mean

Starting with rails 5.2, a thing called credentials.yml.enc is added by default. I think it also exists in your config folder. This can also be used in various places by specifying environment variables.

If both are the same, you can use either one! I think ~

Unlike dotenv-rails, which just sets variables, credentials.yml.enc encrypts and holds environment variables! And there is a difference that it is used in combination using config/master.key.

I don't want to see environment variables, but encryption is important because it's used for things like that!

If you use dotenv-rails and manage important values ​​in .env, when you see the folder in some time signature, it's humming here. If you can see it in .env, it's over.

If it is credentials.yml.enc, even if it is seen, it is encrypted, so it will be a" wakame seaweed ".

bonus

Even if you upload credentials.yml.enc to git, other people can not help unless there is master.key, so you can use it by cloning it at the time of deployment and pulling master.key from the local That's right.

It's clear that this is better from a security perspective.

Just when using credentials.yml.enc

Rails.application.credentials.Set environment variable
#dotenv-rails
ENV['Set environment variable']

long! !! But with VS code, it predicts that you will hit it several times, so there is no problem

And when setting environment variables (with docker)

docker-compose run -e EDITOR="vim" web rails credentials:edit

There is the hassle of opening vim and editing.

By the way, if you get File encrypted and saved., Probably vim is not included, so please install it.

In my case

Dockerfile
#Add apt-get install vim

No, it's interesting because there are still many things I don't know ~

If something goes wrong, please teach me.

Then ~ ⭐️

Recommended Posts

Do you need dotenv-rails?
Do you need a memory-aware implementation of Java?
Do you really need that preload? ~ Utilization of delayed load ~
Why you need a bundle exec
Can you do it? Java EE
When will you do the refactoring?
Do you use Stream in Java?
To you who absolutely need backtrace
How do you write the ternary operator (? :)
What to do if you install Ubuntu