Any recommendations for how to handle config from env vars with Integrant? I like Duct's system, and if I was to write some logic myself, I think I'd do something similar. I'm not sure about how to sanely handle defaults that can be overrdden by env vars, though. I'd love to hear how others have handled this!
I use Aero https://github.com/juxt/aero#hide-passwords-in-local-private-files to load my secrets and env variables
You can use https://github.com/tolitius/cprop to load the integrant config map
idk how that handles env var overrides with the map structure of integrant, relying on 2-vector pairs as keys
but thatβs the closest thing that support env var config overrides out of the box
donβt think integrant involved with env variables
i would recommend aero
Thanks for the references!
Are you using cprop/aero yourselves? Do you just register it in front of your (ig/read-string (slurp (io/resource conf-path)))
in integrant.repl/set-prep!
? I noticed that https://github.com/metosin/maailma#integrant-example allows embedding the ig/ref
reader into the configuration reader, so perhaps something similar is possible with cprop/aero.
I'm curious about how to handle different configuration in dev and prod. Should that be handled totally before the config reaches the init-key
multimethods? Or is it reasonable to use the multimethods as part of implementing a dev and a prod config?
I feel a bit like I'm reinventing the wheel ... And I'd like to avoid constructing layers/logic because I don't know how to use Integrant properly.
@teodorlu i'm not 100% sure what problem you're trying to solve. when i use integrant, i treat the environment as another stateful component. and if there's any other component that depends on some environment variables, i'll make that component depend on that environment component. i also try to keep my command line arguments minimal and store environment specific configurations in separate edn files (e.g., configuration.production.edn
, configuration.development.edn,
etc.) and just run my process with a single environment variable (e.g., ENV=production
or ENV=development
), let the environment component do the heavy lifting (i.e., capturing and interpreting that environment variable to the path to a corresponding configuration, reading that configuration, and then creating and returning a regular map from that configuration for other dependent components to use.)
if what i said makes any sense, you may go ahead and take a look at this repository (https://github.com/finalfantasia/try_integrant) for the details.
Thanks a lot! That kind of discussion is just what I needed.
Using an integrant component for environment variables is a great idea. That could help avoid just the kind of layering I wanted to avoid.
yep π
when i design a system, this (https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) is what i always keep in mind.
also known as, "functional core, imperative shell".
Hmm. I've watched and enjoyed Gary Bernhardt's coverage of Functional Core, Imperative Shell[1]. But I haven't been thinking of it in terms of how to write integrant systems. Thanks for the pointer! I might have to spend some time at the repository you linked to. [1]: https://www.destroyallsoftware.com/screencasts/catalog/functional-core-imperative-shell
yeah, it's a great talk, i watched it as well. i think he actually mentions that pattern (by hexagonal architecture or something similar) in that talk.
another great talk from him that's worth watching is Boundaries: https://www.destroyallsoftware.com/talks/boundaries