Fork me on GitHub
#duct
<
2020-07-18
>
ted15:07:52

Hello, I'm new to duct and was wondering if someone could help me with some project setup. I'm following https://github.com/duct-framework/duct/wiki/Configuration instructiong but based on https://github.com/duct-framework/duct/wiki/Configuration#configedn section is looks like they are a little out of date since the default config doesn't look like that (unless I've gotten a base version). My problem is that following the instructions as they are https://github.com/duct-framework/duct/wiki/Configuration#completed-configuration my completed configuration isn't overwriting :duct.core/environment with :development as I would hope. My project is all default stuff except I have replaced {} with

{:duct.core/environment :development
 :duct.core/include ["image_service/config"]}
in dev/resources/dev.edn per the README. I would assume that when I run (duct/prep-config (read-config) profiles) (from the default dev namespace) it would merge the dev config and replace the environment config. Does anyone know what I'm missing here?

kwrooijen16:07:33

Hmm.. seems like that's an outdated config

ted16:07:18

Well, I have now. Thanks 🙂 wasn't aware of that but I'll take a stab at it

kwrooijen16:07:04

I think I'm going to backup / delete the outdated section, and reference the guide I just linked

kwrooijen16:07:39

Well I don't even need to back it up since it's git

kwrooijen16:07:29

Also, be sure to update your packages after you generate a new Duct project (with for example lein ancient)

ted16:07:49

Hmm, I don't see anything in regards to dev configurations in this guide. I'd be more than willing to write it once I figure it out though

kwrooijen16:07:33

The way dev configuration works is with the profiles system. For example in the config.edn file there is the following like:

:duct.profile/dev   #duct/include "dev"

kwrooijen16:07:23

If the :duct.profile/dev key is passed in the duct.core/exec-config or duct.core/prep-config function, then that profile's EDN file gets merged into your base profile

kwrooijen16:07:22

The following two definitions should be in your dev.clj file

(def profiles
  [:duct.profile/dev :duct.profile/local])

(integrant.repl/set-prep! #(duct/prep-config (read-config) profiles))

kwrooijen16:07:39

Which will make sure that the dev.edn file gets merged into your base config during development

ted16:07:58

Yes, those are there. When I run (duct/prep-config (read-config) profiles) I can see that my dev config has been picked up correctly, but it doesn't seem to be merging it into the base

kwrooijen16:07:23

Strange, that should be the case. Do you have your config online / can you share it?

kwrooijen16:07:01

Oh, I think I know the issue

kwrooijen16:07:01

All your keys need to be top-level in your dev.edn

kwrooijen16:07:32

If you're seeing the keys in the resulting config, but they aren't being merged into your base, then that's probably the issue

ted16:07:43

My dev edn is

{:duct.core/environment :development
 :duct.core/include ["image_service/config"]}

ted16:07:46

Actually, I may still be operating off of suggestions from that old README. If I want duct.core/environment to default to :production would I put that in the base or in the top level?

kwrooijen16:07:18

Does your base have the following format?

{:duct.profile/base
 {:duct.core/project-ns my-app
  ,,,}
 :duct.profile/dev #duct/include "dev.edn"}

kwrooijen16:07:38

Since you're starting off from the old guide, it's probably a bit messed up

ted16:07:41

No, the includes are in the base

ted16:07:03

Lemme try moving them out 🤔 ?

kwrooijen16:07:07

I think the best thing you can do is run lein new duct my-app

kwrooijen16:07:11

And then just restart the guide

kwrooijen16:07:31

Because generating a new duct app (and updating dependencies) should already be enough

kwrooijen16:07:00

And yeah, :duct.profile/dev has to be outside of the base config

ted16:07:58

Ah, OK. Yeah, even generated on has it this way

ted16:07:02

Not sure how I got here

ted16:07:29

Yup, that did it...

ted16:07:33

Thank you 🙇

kwrooijen16:07:02

No problem, a bit of an unfortunate start with that outdated config

kwrooijen16:07:26

Also, in terms of the difference between keys inside of the base config vs outside of the base config:

kwrooijen16:07:14

Any keys outside of the base config are "duct module" keys. These are initiated during preperation (`duct/prep-config`), and modify the base config somehow. All module keys' ig/init-key return a function (fn [config] config) where the fn modifies config (base config)

kwrooijen16:07:36

Might be a bit confusing at first, but I'm not sure if there's any documentation on them either

ted16:07:26

Gotcha, I'm sure it'll start to make sense as I play around with it more

ted16:07:33

thanks again for all the help!

ted17:07:37

Is there an idiomatic way to do local setup tasks? In my case I just want to ensure that a bucket exists in a local minio container

kwrooijen17:07:53

You could add a key to dev.edn with an init-key that's dev only

ted18:07:48

That's a cool idea! I feel like a real dumb dumb for just now starting to use integrant

kwrooijen19:07:18

Integrant can be very powerful once you get the hang of it