Rails - Resolve .env conflicts between development and Kamal deploy
Problem
We often use the gem Dotenv to handle environment variables on development machine or gem Foreman also automatic load ENV from .env file (Forceman - Per Process Environment Variables)
The problems is Kamal-deploy use .env too, for the deployment on target service. The command `kamal envify` will build the .env file from env.erb file, and use that .env as input for other command
Solution
Use gem Dotenv in your development repo, then create an .env.development or .env.development.local file to store ENV for development, don't use .env file
group :development, :test do
gem 'dotenv', '~> 3.1'
end
Then in application.rb, add an config to ignore .env file
Dotenv will load variable from other .env file and ignore all content from .env.