bkeepers / dotenv

A Ruby gem to load environment variables from `.env`.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[would be great if] dotenv supported "source" from other envs

palladius opened this issue · comments

I have a somewhat complicated .env.{dev,staging,prod} which

source .env.common-pre

RAILS_ENV="staging"
MYSQL_ROOT_PASSWORD="blah"
MYSQL_USER="user"
MYSQL_PASS="blah"
MYSQL_HOST="1.2.3.4"
MYSQL_DBNAME="mydb"

source .env.common-post

All three environemnts source a common .env fragment at the beginning and end. In bash it works like a charm, of course.

I use dotenv for everything programmatic like passing env vars to docker, docker-compose and I LOVE it.
I would love if dotenv was able to expand on additional .env based on bash command "source".

You can already do something similar by explicitly configuring Dotenv.load order.
Example:

Dotenv.load(".env.common-pre", ".env.dev", ".env.common-post")

If you want .env.common-post to override the other values you could

Dotenv.load(".env.common-pre", ".env.dev")
Dotenv.overload(".env.common-post")

Or if you must reuse some bash files , you could probably do something like whats explained in this stackoverflow post, and integrate it with Dotenv
https://stackoverflow.com/questions/1197224/source-shell-script-into-environment-within-a-ruby-script