hey everyone, Im trying to to make duct read configuration from env vars (this part is ok!)
but im trying to find a way, in development and in test, to export specific env variables
is dev/resources/dev.edn
the right place to do so? (I intend to commit these default values)
Im aware that I can use default values like
{:port #env ["PORT" Int :or 3000]}
but Id like to avoid default values production
so Ideally the application always reads from env, and when Im developing or run lein test
other env variables are usedYou can override the keys in your dev/test profiles. So in your base profile (which will filter through to prod) you can have {:port #duct/env ["PORT" Int]}
, and in dev/test {:port #duct/env ["DEV_PORT" Int :or 3000]}
.
so I have to duplicate the edn file structure in the test profile?
but change only the :port
field?
sorry for the noob question but where is my dev/test profile?
I need to create one for test?
I'd recommend creating a sandbox project with lein new duct sandbox
to have a "live" example you can play with
The default config looks like this:
{:duct.profile/base
{:duct.core/project-ns sandbox}
:duct.profile/dev #duct/include "dev"
:duct.profile/local #duct/include "local"
:duct.profile/prod {}
:duct.module/logging {}}
done 🙂
With an empty dev config in dev/resources/dev.edn
yep!
> so I have to duplicate the edn file structure in the test profile? No, integrant is smart enough that you can only override the keys you want to change
So if you have {:some/component {:foo 1, :bar 2}}
in your base profile, and {:some/component {:foo 10}}
in your dev profile, the component will end up getting initialized with {:foo 10, :bar 2}
this is cool 🙂
FYI, this is used by duct for merging configuration: https://github.com/weavejester/meta-merge You can see all the options you have with this
thank you so much for you detailed explanation
np 🙂
so -main
is not executed when we use the repl?
when its executed?
lein run
lein run
runs it with the production profile unless we specify otherwise then?
lein run
will always run the production profile, given the default main.clj
Note the profiles [:duct.profile/prod]
on main.clj
's line 9
how can I specify other profile? lein with-profile :duct.profile/my-profile run
is not working
lein profiles != duct profiles
hmm I see
You'll need to update that profiles
vector in main.clj
... if you want to run a different profile from lein run
For dev, that's usually not necessary
you are right
You should rather lein repl
, and then (dev)
and (go)
and when running tests
See dev/src/dev.clj
and dev/src/user.clj
to see what that does 🙂
lein
test should load the test profile, right?
Yes.
it happens out of the box or some configuration is needed?
looks like lein test
is using the prod profile
Tbh, I'm not sure
well Ill try to find out thanks once again 🙂
Ah, I see now. We added a test fixture that inits the duct system, and it takes a profile arg to specify the profile to use (we have :test
and :test-e2e
profiles). Each test uses that fixture then: (use-fixtures :each (hh/system-fixture :test))
Ill try that thanks 🙂