Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
palladius opened this issue Jan 24, 2021 · 1 comment
Open

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

palladius opened this issue Jan 24, 2021 · 1 comment

Comments

@palladius
Copy link

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".

@CorbanR
Copy link

CorbanR commented Nov 15, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants