jezdez / envdir

A Python port of daemontools' envdir.
https://envdir.readthedocs.io/
MIT License
229 stars 28 forks source link

Allow envdir to expand existing shell values #27

Open jdunck opened 10 years ago

jdunck commented 10 years ago

In bash, you can do things like: export PATH=$PATH:/some/new/path

It would be nice if envdir supported similar expansion.

The original envdir.c doesn't support this, so you may be reluctant. However, in trying to do 12-factor apps, I've found it useful to have, for example, resource prefixes so that you can have jenkins builds like so:

DATABASEURL=postgresql://localhost/db$JOB_NAME

Thoughts?

abevoelker commented 10 years ago

I was just trying to get this functionality to work - it would be awesome if it was supported. It's useful when using Docker in development, because when linking containers you have to re-use dynamic configuration exposed via environment variables.

For example:

REDIS_URL=redis://$REDIS_PORT_6379_TCP_ADDR:6379
blueyed commented 10 years ago

Do I understand it correctly, that the variables are meant to be expanded also from the envdir's files contents / are variables meant to be substituted from other envdir files/variables?

What would happen with a file that provides A=$Z and Z=$A? (error?) Or with A=$Z and Z=foo? (setup the env using a dependency tree?)

RonnyPfannschmidt commented 9 years ago

this is not part of the standard behavior, i think a separate command name with substitution support could be used, of course failing on recursion

abevoelker commented 9 years ago

I don't actually need this anymore, so you can ignore my original +1. /unsubs

piotr-dobrogost commented 8 years ago

The original envdir.c doesn't support this, so you may be reluctant.

But you should not be as this would be a very nice feature to have :) What do you think @jezdez?

Btw, another problem with using environment variables in the context of envdir is explained at http://thedjbway.b0llix.net/daemontools/envdir.html Look for paragraph which starts with

At the risk of redundancy, we would like to note one of the potential "gotchas" in using envdir with run scripts.

dozymoe commented 2 years ago

Can you limit it to only expanding itself? For now. export PATH=local/bin:$PATH is a common usage of custom env.

Stratus3D commented 1 year ago

I'm searching for a tool similar to envdir that fits my use case. I figured I'd describe my use case here (full shell expansion) so that either someone may direct me too a tool better suited for me, or weigh in on how difficult it would be to create a fork (and/or PR) of this project to add support for it.

I have some values stored on disk in files (just how envdir expects them), but I'd like to define shell expressions inside the env files that compute the environment variable value. I'd like to do this because I don't want to store secrets on disk. Most of my environment variables don't store secrets, but because this is for a 12 Factor app some secrets will need to available via environment variables. Additionally, there are different places secrets need to be pulled from, OS keychain, password manager CLI, etc... For example, I might want to pull something from 1Password:

$ tree
envs
└── SUBMARINE_HATCH_PASSCODE

0 directories, 1 file 

$ cat envs/SUBMARINE_HATCH_PASSCODE

$(op item get --vault top-secret 'submarine hatch' --fields code)

Any suggestions on how to achieve this with envdir? Or is there another program I should look at? Thanks!