Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[DI] Allow ENV vars to be not defined when compiling the container #25010
I have a CI build & run pipeline.
The current implementation of the DI component requires to have all the ENV variables used in the config files as "defined" in the warmup environment, and this is really annoying...
I'm forced by this the to re-define all of them (with some default values) inside a file like
There are too many env files to maintain:
Can the variable existence check be omitted? Default to
It is a common thing that in the "build" environment env variables are different from the "run" envs and having to define them just to have a default is annoying.
This is tricky. Yes, we do want the user to be able to build their container without being in an environment that has all the env vars. But my current opinion is that you should simply not have any services used during the cache warmup process that require env variables (this logically makes sense). If you somehow are trying to use a service that needs an env var at warmup, that’s a bug.
What env vars do you see being required?
About the Doctrine situation, there is a recipe PR (by me) that may fix this requirement.
The doctrine warmup needs to know only the server version, all the other parameters as username, host or password are useless.
In this case my env file could be just
While now i'm forced to have
This could be a solution, but the
I disagree. Env vars are just configurations and the cache warmpup might need configurations too.
If a warmer needs configurations why not allow them to have it.
EDIT: Ok, I see that the old configurations in the doctrine-bundle are still available so the
referenced this issue
Nov 19, 2017
actually I agree with this statement: reading the env at build time means hardcoding a value that should be dynamic in the first place. Reading an env var as part of the cache warmup process defeats the usefulness of using en vars, so that a simple parameter should be used instead.
env vars should be used only for infrastructure related configuration, ones that change between the build machine and the prod or dev machines.
for app-related configuration, regular parameters should be used instead.
@nicolas-grekas ok, I got your point.
But then the question is: How to allow to run
My proposal was to just set them to
for DATABASE_URL, @weaverryan has a solution, which is setting the serverVersion using a regular parameter, then ensuring that this is enough for Doctrine to not need a connection, even uninitialized (could be the case, dunno).
Yes i kwew it and i've commented it here #24927 (comment)
actually no services are needed, it is just that the container won't compile if the used env variables are not defined.
I've did a second check on my app and I have to admit that you were right.
Thanks for the support and patience, I think my issue was "invalid", Maybe a bit influenced by the "DATABASE_URL" unexpected behaviour but after setting "serverVersion" things are going well!
Closing the issue