-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Making possible to define configuration by environment #12361
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
Making possible to define configuration by environment #12361
Conversation
@jalogut Thank you for this nice developer feature contribution! Please can you fix the failing unit test? Thanks! |
- Add new file config_env.php into the config pool - Add CONFIG_ENV_MODE in env.php to be able to specify the system environment
767f7ce
to
66edfb8
Compare
@mzeis thanks for noticing. All green now. |
After much discussion in the ENGCOM, we concluded this would also allow addressing some of the issues outlined in #4955 -- it would provide an "untouchable" configuration pool, from which things can be extended. Because it doesn't override env.php, configuration would need to be omitted form that to be merged in with this file. Edited: With more thinking / discussion, I think the ideal naming for this is
I understand this is a breaking change, and I am not suggesting this make it into this PR. However, I would consider it for refactoring between 2.2 and 2.3 |
Hi, Vaimo has implemented internally similar feature that updates core_config_data table contents when setup:upgrade is called (from recurring setup). One of the issue in this proposal is that config_env.php is a PHP array, which is not easy to maintain or read. Perhaps there are some room to combine these efforts? Our YAML format as an example: "*": # Applies to all environments, including local and jenkins build
- path: [ dev/js/merge_files, dev/js/minify_files, dev/css/merge_css_files, dev/css/minify_files ]
value: 1
scope: default
scope_id: 0
live: # Applies to live environment
- path: dev/js/minify_files
value: 1
# When using scope default and scope_id 0, they can be omitted
qa:
- path: [ web/unsecure/base_url, web/secure/base_url ]
value: https://qa-base-url.example.com/
LOCAL: # Applies to local development installations only
- path: [ dev/js/merge_files, dev/js/minify_files, dev/css/merge_css_files, dev/css/minify_files ]
value: 0
- path: klevu_search/general/enabled
value: 0
- path: integration/general/api_key
delete: true # will cause config option with this path to be removed (only from default scope!) |
Hi @pavec, We also use |
Hi @jalogut There is another way to set these values per environment - using environment variables: In your case, you need to pass next variables into your
These are absolutely top priority configs which will overwrite values in |
Hi @shiftedreality , I did not know that, thank your for pointing it. That would be exactly what I was looking for 😀 |
@jalogut, I thought you wanted to keep your env-specific values in git? Anyway, good to see that built-in solution works for you. |
@antonkril, yes, I still want that and I’d very happy if the PR gets merged. However, if it doesn’t, it is nice to know that there is an alternative. Only drowback with the
Including that by default in |
@jalogut I would like to add more thoughts on this item: So the reason, why do we have 2 config files now - is separating
#app/etc/dev.php
$envConfig = file_exists(__DIR__ . '/env.php') ? require(__DIR__ . '/env.php') : [];
$envMode = isset($envConfig['CONFIG_ENV_MODE']) ? $envConfig['CONFIG_ENV_MODE'] : []; |
Hola @shiftedreality; For me at least, the problem with both pools (env.php and config.php) is they're both application managed -- one cannot stub third party credential management, such as vault etc; the file is overwritten periodically. This PR provides a "sacred" file, which no one touches. Stubbing it in the environment is usually possible (I also didn't know about this feature -- cool!) but perhaps more difficult? I'm unsure. |
Hi, any updates on this PR? Do you think that would be merged? |
Hi @jalogut , generally solution looks good for me, but I have several concerns regarding you implementation:
As an alternative solution, please, consider to refactor logic by using two folders:
This solution similar to Linux files configurations and will be more familiar for people. |
This is a lovely API. |
Hi @jalogut , are you going to continue progress with PR? |
Hi @sidolov unfortunately I do not have much time atm. So I would be glad if someone takes over. |
Just noticed that it is possible to define environment specific config settings in An alternative solution to this PR could be to have modules with different settings in their I still like more the solution of this PR but just wanted to leave that here as documentation of other possible options. |
Hi @jalogut , I'm closing this PR due to inactivity. |
Description
Add new file
config_env.php
into the config pool:config_env.php
can be in VCS and add specific configurations by environment. This file updates values inconfig.php
butenv.php
has still the highest priorityAdd
CONFIG_ENV_MODE
inenv.php
to be able to specify the system environment:CONFIG_ENV_MODE
can be set into theenv.php
to specify the config environment mode to load the config settings.Fixed Issues
The new deployment pipeline added on 2.2 makes possible to propagate configuration to a live server. However, that introduces new issues as it is not possible to specify such configuration by environment. See following example:
Situation
config.php
we specifydev/js/merge_files = 1
anddev/css/merge_css_files = 1
config.php
because is the only configuration file under VCS and same configuration is needed on thebuild
system.build
andPROD
environments as they need same configurationProblem
config.php
the only way to modify that on my local is by manually adding the corresponding configuration onenv.php
.env.php
(or executing commandconfig:set --lock path value
)env.php
is not in VCS, so you need to manually edit theenv.php
every time you install a project locallyconfig.php
for production and build server. He has no way to add the corresponding for local env to ensure that those changes will not break the local installations of his colleagues. For example enabling varnish cache onconfig.php
. Next time the other developers checkout the latest version of the project, it will break their local installation as they do not have Varnish.Alternatives Solutions that do not work
Discussing that in Slack, Anton Kril suggested to use condition statements inside
config.php
that return different configurations depending onenv
variables. Although that works, these statements are gone as soon as you execute any command that edits theconfig.php
. That is the case forapp:config:dump
ormodule:disable/enable
. Because of that, it is not possible to properly maintain those condition statements insideconfig.php
.Manual testing scenarios
These changes allow keeping configuration by environment like that:
Possible to define in
env.php
type of environment for config settingsUse environment type inside
config_env.php
to overwrite default settings inconfig.php
As you can see in this example, thanks to that, we can assure that all developers will have
merge_files = 0
andTddWizard_Fixtures
module enabled on their local environments. That modifies theconfig.php
which is meant forPROD
andBUILD
systems but it is shared among all environments.Contribution checklist