Oppskrift / oppskrift_api

0 stars 0 forks source link

Changing dotenv strategy #8

Closed Djyp closed 3 years ago

Djyp commented 3 years ago

I'd like to have this architecture with .env files where the .env is a commited file and we .gitignore a .env.local that overrides some variables. It's what we do in Symfony and it is way better because you don't need to create a .env from the .env.dist, it's already there, you just need to customize vars with a .env.local when needed.

It allows us to set default values and give a way to override them. It's easier to maintain an instance because the new vars are commited and they appear automatically on every update.

.
├── .env (commited file, it contains all needed vars with basic values)
├── .env.local (ignored file, it overrides the basic values with the environment specific ones)
├── .gitignore

The usual case is with DATABASE_URL, but can happen with any variable.

.env

ACTIVITY_PUB_ACTIVATED=1
MULTI_LANGUAGE=1
DATABASE_URL=postgres://username:password@localhost/diesel_demo

.env.local

DATABASE_URL=postgres://[THELOCALUSERNAME]:[THEREALPASSWORD]@localhost/[THELOCALDBNAME]
MULTI_LANGUAGE=0
Scttpr commented 3 years ago

Ok for me, it's a good opportunity to setup a better (more flexible) dotenv crate where you can have a thiner config.

Scttpr commented 3 years ago

I have checked possible crates, maybe this one is a good way to provide thiner configurations : https://github.com/sagiegurari/cargo-make

It's rich and with dedicated toml files, looks a lot more idiomatic to Rust eco-system, what do you think ?

Djyp commented 3 years ago

months later : Adding cargo-make is quite a big change for something I am not yet mastering. I think I was trying to be perfect and I'm now accepting actix as is. It's an optimization on a non-essential matter.

I'd rather close the issue.