-
Notifications
You must be signed in to change notification settings - Fork 5
Introduce mode-specific config files #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
414ede1 to
b72dcfc
Compare
c2c6364 to
2416bff
Compare
|
I talked about this with @jordanguedj , he seemed ok with having to manage the base_url and oauth_token in the infra |
streino
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't what I had in mind when discussing on Tchap.
My proposal is to have a CONFIG_PATH env var that will contain the path of the config.yaml you want to load. Then this CONFIG_PATH var can be set in a .env or .env.$env to be loaded automatically.
I see two problems with the approach of this PR:
config.yamlisn't the only source of truth anymore. You now have to look into two different locations to know about config.VITE_SITE_IDis an exception because it serves a similar purpose toCONFIG_PATH, ie we have to know where to look for the config. Note that if we were to separate code and config we wouldn't needVITE_SITE_ID(because there would be a single site on a given repo), and if we use per-env branches, we don't needCONFIG_PATH. Combine per-branch and per-site and you have a singleconfig.yamlthat you know where to find, and which remains the single source of truth.- If you start extracting parameters from
config.yaml, there's no end to it. Next you'll want to extract the matomo id, then maybe the site notice, then...
In the future we may want to have a way to override config.yaml params with env-vars as this is a common pattern used eg in the docker world. But 1) I don't think we need it yet, and 2) this is different from extracting parameters one at a time, we'll want to have a generic mechanism for it.
|
Oh ok, yeah I didn't exactly get what you meant on Tchap. Managing your env-dependent variables in env variables is quite standard, so I don't understand the resistance you oppose here. Yes the matomo ID should be in an env variable too. Yes the notice "you are on a demo version" should depend on I want to be able to take the main branch, and push it on any vertical. I don't want to manage different configurations in different branches. Env vars are made for this. Let's use them. |
Then where does it stop? And what if different verticals want different banners? Or a banner in prod? (at some point we had one on ecologie). We could argue that for that specific banner config we don't need it, but you get the general idea: each thing you'll want to configure per-env will have to be extracted from the config.
A couple reasons I'm not fond of envvar-only approach:
This all is less true if you start overriding config with envvars, but still is better than envvar-only. I'm not saying envvars shouldn't be used at all, but I strongly prefer to put as much as possible in config, and to put it in config first, then leave the possibility to override with envvar, for those contexts where it makes sense, like the one you explain. So I'm open to a PR that would allow overriding config settings with envvars in a somewhat generic way (even a first PR that does is sort of adhoc but with the intent of going the generic way). But I'm really not in favor of extracting config bit by bit and have it become less consistent and less maintainable (from the POV of a vertical devops). |
|
I can see your point. I'll propose a solution that :
I'll get cooking and will let you know. |
|
I still fail to grasp why branches don't work for you. Agreed it's not "the same (machine) code" in the sense that you build each branch separately and so it may not be identical to the bit. But it still can be "the same (source) code" when you sync the branches (cf what we do on ecospheres/ecologie.data.gouv). This seems like a good-enough approximation of "the same code", at least until we deal with #809 and can have several config-repo branches pull the same code-repo lib. But if this doesn't work for you, no problem to look at other proposals. In the mean time I'll flag this PR as "needs changes" to make its status easier to figure out. |
|
I'm very uncomfortable with having config bits isolated in specific branches for specific environments because :
Hehe 🙈 I'm trolling but not really trolling. I was really confused when I arrived on the repo. I couldn't understand how the If it was in an env variable, I would have assumed this variable is properly set on the production machine, like most of the projects I've encountered so far. But I get your point, we can and should keep most of the configuration in the codebase for all the reasons you cited. I think I'll have time to work on something tomorrow. |
We definitely should fix that part in #778. But I'm not sure why you'd figure envvars would be set somewhere else, but not config files? Would it have helped to leave some values blank (or fill them with dummy data) in the config to make it more explicit? Basically, do you have specific suggestions about how to make it more understandable for a newcomer? I repeat myself, but I also think having separate config repos will help. Aside from the doc, you seem more used to envvars, but deploying from branches is also a very common pattern (we could name the branches better for discoverability). In the end, having config in envvars or files doesn't change the fact that you have to have different versions of (at least some of) the config for different deployments ; versions which eventually end up in files anyway, in an ops repo (Ansible in our case, which we don't control), in deployments notes (can get out of sync), or whatever means you have to store config. So basically you have a single branch with a bunch of files with different versions of a config ( That said, having finer-grained control of how you split/override config to avoid redundancy would be nice indeed, and it's great if you can propose a way to do it without adding too much complexity. |
streino
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed above
308e882 to
2f6a489
Compare
|
Here is my new proposition ☝️
|
(I don't want to define the whole config object, but maybe I should)
|
Will review asap. |
|
I don't think we (and any other site?) will use this. We want to keep a branch in sync with what is deployed on a given env (code + config), so we'll stick with the current system (a config file customized by env on a branch). The PR workflow is also quite cool for deployment. It will also make the maintenance of the config file (which is a pain) a bit more arduous, since we'll have more files to check for migrations if any. If it's really a blocker, why not I guess, but I'm not sure this is really needed. |
You still can. All branches are going to be in sync with main which contains all configs. So any specific deployment branch will be in sync with what is deployed on a given env (code + config). And you can give the option
This will make it easier to maintain. Any change in the config can directly be applied to all the config files in the PR responsible of the change. No more conflicts when merging And there is only like 3 values in a mode-specific config, thanks to the deep merge. So not that much to maintain. |
I agree we (ecologie) will probably stick to branch-based deployment for a bunch of reasons1. But if other verticals want to live in
Famous last words ;) But whoever wants to use this, why not.
I think it's fair to say that whoever uses per-env config overrides is in charge of keeping their overrides in sync. We can't request core devs or people from other verticals to patch more than the base config in (other) verticals. This will change anyway if/when we extract config into separate repos since each vertical will have to maintain their own configs (but on fixed library releases, so it won't be as chaotic as it is now). @abulte I'll take a look at the code, but can you as well ? 🙏 Footnotes
|
I repeat : this is not challenging the branch-based deployment. I don't understand why you both say that. |
vite.config.mts
Outdated
| routeFile.includes(`custom/${env.VITE_SITE_ID}/routes.ts`) | ||
| ) | ||
| } | ||
| // Include only the current mode's config file in the bundle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be completely off, but IIUC this is a build-time action and we then deep-merge at run-time? If so, why not merge at build-time and only have a single config object to manipulate at run-time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't manage to expose the merged config by merging it at build time. If you know how to do, I'll be glad to get your advice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm the front-end noob here, so this is really a question.
If someone else has a suggestion (maybe Claude ?) then cool, otherwise nevermind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like that seems to work #846.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment to that PR, but TBD here if it gets merged.
src/config.ts
Outdated
| import merge from 'deepmerge' | ||
|
|
||
| export default config | ||
| const mode = import.meta.env.MODE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name is a bit too generic. Maybe something like DEPLOYMENT_ENV? I've seen ENV in other contexts but I don't know if this'll conflict in the present case?
I'm not sure I understand how .env.* varations are loaded, but can't we piggyback on that mechanism to get the value we need, instead of redefining it in a new envvar?
Also, if we end up introducing an envvar, will need doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a new env var. "MODE" is defined by vite : typically "development" with npm run dev and production with npm run build; npm run preview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use the NODE_ENV if you prefer, this is the same in most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok I thought this was a new setting. I can't say which one it preferable, so maybe @abulte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vite might be slightly "better".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vite might be slightly "better".
What do you mean ? Are you talking about "MODE" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about this in my bed yesterday (yes), and I think this will require a minor change in the infra to pass the --mode demo (or preproduction) at build time for the demo (or preproduction) environments. Otherwise, they will be treated as production, and thus will use the production config.
I'm not saying it's challenging another model (and I don't think @abulte is either). Just that this adds (limited) complexity, and another way to do things ; meaning possibly more room for ambiguity and/or maintenance. And for a gain we have a hard time evaluating at this point (ie we don't who other than you will use it), because we recommend going with branch-based deployments and so far it's worked out well enough. IMO your latest proposal is okay, and we're not saying no. But while each PR doesn't add much by itself, in the end it's code we'll have to maintain, and we're a small team with limited time to dedicate to the front-kit. So we try to keep things simple (at least by some definition of simple 😬) and try to stick to a single way to do things. It's necessarily a balancing act. |
* chore: merge config at build time * comment * Use ViteRestart to detect config changes (#865) --------- Co-authored-by: streino <[email protected]>

Override the
VITE_DATAGOUV_BASE_URLandVITE_DATAGOUV_OAUTH_CLIENT_IDin your deployments scripts, the same way you already override theVITE_SITE_ID.You can find the suitable values of
VITE_DATAGOUV_OAUTH_CLIENT_IDfor each site in their respective config (Except ecospheres which has 2 values for demo and prod in their respective branches).Here is all the links to all the existing oauth_client_ids (before merging this PR) :
ecospheres demo
ecospheres prod
meteo-france
defis
hackathon
logistique
simplifions