[MAGNOLIA-7883] Enable different configuration for different environments Created: 21/Sep/20 Updated: 22/Sep/22 Resolved: 20/May/21 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | None |
| Affects Version/s: | 6.2.3 |
| Fix Version/s: | 6.2.9 |
| Type: | Story | Priority: | Neutral |
| Reporter: | Christopher Zimmermann | Assignee: | Maxime Michel |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | freetrials | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Template: |
|
||||||||||||||||||||||||
| Acceptance criteria: |
Empty
|
||||||||||||||||||||||||
| Task DoD: |
[X]*
Doc/release notes changes? Comment present?
[X]*
Downstream builds green?
[X]*
Solution information and context easily available?
[X]*
Tests
[X]*
FixVersion filled and not yet released
[X] 
Architecture Decision Record (ADR)
|
||||||||||||||||||||||||
| Release notes required: |
Yes
|
||||||||||||||||||||||||
| Documentation update required: |
Yes
|
||||||||||||||||||||||||
| Date of First Response: | |||||||||||||||||||||||||
| Description |
|
As a developer, I want to be able to provide different configuration to different environments, so that I can handle the different needs of the different environments such as dev, integration and production. Context Configurations can be supplied in light modules or Java modules. Typically, the same definition configurations are used in all environments, with the only thing changing being the new configuration that is being tested. However in some cases we want different configurations in one or more of these environments, for example we may want a restClient to point to a sandbox API while in development, but point to a production API while in production. Or on a site definition, we might want to use differnet domain names based on environment. Bigger Picture Consider the related need of applying differnet configurations to author and public instances within each of those environments as well. See: https://jira.magnolia-cms.com/browse/MAGNOLIA-7882 |
| Comments |
| Comment by Maxime Michel [ 20/May/21 ] |
|
What we ended up implementing is that, only when the (new) feature flag magnolia.yaml.envsubst is set to true, i.e. -Dmagnolia.yaml.envsubst=true, then the following syntax in a YAML file: baseUrl: !env https://${ENV}.api.com/endpoint Will parse the environment variable ${ENV}. Property can of course be anything, not only baseUrl. Same with the environment variable, $ENV is only an example. Important note: this won't work in YAML decorator files, only in plain YAML definitions. |
| Comment by Christopher Zimmermann [ 02/Jun/21 ] |
|
I can have multiple environment variables right? BASE_URL PREVIEW_URL MY_BUNNY_FACE etc? Then faces: !env https://${MY_BUNNY_FACE}/eyes |
| Comment by Christopher Zimmermann [ 02/Jun/21 ] |
|
Where does it read the variables from - only from the system itself - or is it possible to supply a file - similar to '.env' in frontend frameworks? Or other locations? |
| Comment by Maxime Michel [ 02/Jun/21 ] |
I have not tried that but I don't see any reason why not.
The util we use to do the substitution has a couple of options: "Base64 Decoder: ${base64Decoder:SGVsbG9Xb3JsZCE=}\n" That being said, we chose to only allow environment variables for now. For the .env file, I think that's a good suggestion, but I don't think it's the same mechanism. Magnolia shouldn't be looking up environment variables in the .env file when it comes to resolving them. Instead, it should convert read the .env file and export the environment variables as soon as the light module gets loaded. |