One of the tenants of the 12factor application is to store configuration in the environment. Often, for production environments, the environment is added as a .env file during the deploy. For many languages there are libraries to set this up from inside the application.
However:
In a shell, I often solve this by doing env $(cat /where/my/application/is/.env | sed '/^#/d' | xargs)
. But lets be fair, no one ~~remembers that~~ wants to type that much!
Meet B(etter)env. benv
simply loads a .env
file into the environment and starts an application.
Via Cargo:
$ cargo install benv
From source:
$ git clone https://github.com/timonv/benv
$ cd benv
$ cargo build --release
$ cp target/release/benv /somewhere/in/your/path
```
$ benv
$ benv my/file echo $MYVARIABLE $ benv .env bundle exec rails $ benv .env cargo run $ benv .env npm start $ benv .env mix phoenix.server $ benv .env my_binary
And so on! ```
See benv --help
for more options.
Current benv has to keep running (there should be little overhead). Using libc to properly daemonize is on the wishlist.