duct

plins 2020-06-26T21:12:58.185200Z

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 used

walterl 2020-06-26T21:38:35.186800Z

You 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]}.

plins 2020-06-26T21:41:31.187800Z

so I have to duplicate the edn file structure in the test profile? but change only the :port field?

plins 2020-06-26T21:41:57.188100Z

sorry for the noob question but where is my dev/test profile?

plins 2020-06-26T21:42:05.188400Z

I need to create one for test?

walterl 2020-06-26T21:50:13.189300Z

I'd recommend creating a sandbox project with lein new duct sandbox to have a "live" example you can play with

walterl 2020-06-26T21:50:35.189700Z

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 {}}

plins 2020-06-26T21:51:02.190Z

done 🙂

walterl 2020-06-26T21:51:10.190200Z

With an empty dev config in dev/resources/dev.edn

plins 2020-06-26T21:51:15.190400Z

yep!

walterl 2020-06-26T21:52:05.191600Z

> 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

walterl 2020-06-26T21:53:15.193600Z

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}

plins 2020-06-26T21:54:31.194200Z

this is cool 🙂

kwrooijen 2020-06-27T08:04:33.208800Z

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

👍 1
plins 2020-06-26T21:54:43.194600Z

thank you so much for you detailed explanation

walterl 2020-06-26T21:59:35.195Z

np 🙂

plins 2020-06-26T22:19:10.196300Z

so -main is not executed when we use the repl? when its executed?

walterl 2020-06-26T22:19:55.196800Z

lein run

plins 2020-06-26T22:20:02.197100Z

lein run runs it with the production profile unless we specify otherwise then?

walterl 2020-06-26T22:21:21.197800Z

lein run will always run the production profile, given the default main.clj

walterl 2020-06-26T22:21:46.198100Z

Note the profiles [:duct.profile/prod] on main.clj's line 9

plins 2020-06-26T22:22:34.198500Z

how can I specify other profile? lein with-profile :duct.profile/my-profile run is not working

walterl 2020-06-26T22:23:29.199100Z

lein profiles != duct profiles

plins 2020-06-26T22:23:35.199500Z

hmm I see

walterl 2020-06-26T22:23:46.199800Z

You'll need to update that profiles vector in main.clj

walterl 2020-06-26T22:23:59.200100Z

... if you want to run a different profile from lein run

walterl 2020-06-26T22:24:07.200400Z

For dev, that's usually not necessary

plins 2020-06-26T22:24:45.201100Z

you are right

walterl 2020-06-26T22:24:54.201400Z

You should rather lein repl, and then (dev) and (go)

👍 1
plins 2020-06-26T22:25:06.201800Z

and when running tests

walterl 2020-06-26T22:25:24.202700Z

See dev/src/dev.clj and dev/src/user.clj to see what that does 🙂

plins 2020-06-26T22:25:34.203Z

lein test should load the test profile, right?

walterl 2020-06-26T22:25:49.203200Z

Yes.

plins 2020-06-26T22:26:05.203600Z

it happens out of the box or some configuration is needed?

plins 2020-06-26T22:26:55.204400Z

looks like lein test is using the prod profile

walterl 2020-06-26T22:26:55.204500Z

Tbh, I'm not sure

plins 2020-06-26T22:27:10.204900Z

well Ill try to find out thanks once again 🙂

walterl 2020-06-26T22:33:18.207300Z

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))

plins 2020-06-26T22:41:34.208700Z

Ill try that thanks 🙂