kit-clj / kit

Lightweight, modular framework for scalable web development in Clojure
https://kit-clj.github.io/
MIT License
473 stars 44 forks source link

Reading .env or config.edn files by default #78

Open crimsonhawk47 opened 1 year ago

crimsonhawk47 commented 1 year ago

As a new user I've been struggling with this for a while. From what I can tell, system.edn uses aero to read environment variables, but it has no ability to read from actual .env files.

Since Integrant is so central to the kit workflow, it'd be great if there was already a bootstrap in place for reading from either .env or config.edn files. It's standard to have local environment files that aren't in version history. I, however, have had trouble finding a way to "export" these locally defined variables before integrant's config is read.

There doesn't appear to be anything for this at the moment.

yogthos commented 1 year ago

It might be worth asking regarding .env usage on the aero repo to see if there is a recommended way. With regards to using a config.edn, that should be addressed by the system.edn itself. Environment configuration is treated as part of the Integrant config.

crimsonhawk47 commented 1 year ago

It might be worth asking regarding .env usage on the aero repo to see if there is a recommended way. With regards to using a config.edn, that should be addressed by the system.edn itself. Environment configuration is treated as part of the Integrant config.

I did find a half solution in the aero docs, but the way I implemented it is maybe not what others want. Maybe there's a version of this that could be included in the default kit bootstrap.

Obviously you wouldn't put secrets directly in system.edn. In Aero, they recommend not using the system environment either. They recommend using the #include macro to include other .edn files.

Here is what I did.

{:secrets #include #profile {:dev "../dev-config.edn"
                             :prod "../prod-config.edn"
                             :test "../test-config.edn"}}

I'm including the file directly in aero, which may not be desirable to others. The path has to be relative to system.edn unless you make a custom resolver. Others may want to make a custom resolver and include it in kit.guestbook.env/defaults, aliasing it with secrets.edn and then the system.edn file could just look like this.

{:secrets #include "secrets.edn"}
yogthos commented 1 year ago

I think that's a reasonable solution. Perhaps updating the environment page to mention this approach might be a good solution for now?

vollcheck commented 1 week ago

Here's the PR that addresses storing secrets. What is your opinion on making "secrets" file a part of the template?