Skip to content

Prevent overriding environment variables with --envfile #5802

@evandam

Description

@evandam

Hi folks,

I'm not sure if this is considered a bug or "expected behavior," but --envfile overwrites any existing environment variables, which seems like the opposite of other dotenv libraries such as https://github.com/bkeepers/dotenv.

Similarly, it seems like if godotenv was used instead of a custom parser, this logic would be the same: https://github.com/joho/godotenv#precedence--conventions

For example, I would expect FOO to be system, but instead Caddy reads .env here:

$ cat .env
FOO=.env

$ FOO=system caddy run --envfile .env --environ
...
FOO=.env
...

If this is expected behavior, would it be possible to get an optional flag to prevent this from happening?

For example, a common use case may be to have a Kubernetes ConfigMap mounted with environment-specific environment variables, but you still want to have a .env file to fallback on, if it makes sense.

I opened a PR if it's alright, looking forward to hearing your thoughts 🙌 #5803

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐞Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions