-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[RFC][DX] Defaulting missing env variables to empty string #31497
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
Comments
I think this makes sense if it's explicitly enabled by a flag like you suggest - we similarly don't know the runtime values in advance so can't set placeholders |
To me the best practice would be to list them in the .env file, instead of using parameters. |
Yes @nicolas-grekas, but .env using is discouraged in prod environments, and I'm having this issue while building for that env. Also, as rightly pointed out by @linaori on Slack, it seems that the errors stems from the fact that we have a "chicken and egg" kind of issue, with |
It's not discouraged anymore, it's actually always loaded now. See |
@nicolas-grekas is there somewhere I can catch up on the discussion around that change? |
@nicolas-grekas See for example here: https://github.com/symfony/recipes/blob/3b19bd94886555df1997b441b6cf6a1fab088f3a/doctrine/doctrine-bundle/1.6/config/packages/doctrine.yaml#L2-L6 Workarounds like this are necessary for a successful |
@ciaranmcnulty I think https://symfony.com/blog/new-in-symfony-flex-1-2 could be a good start |
@nicolas-grekas If I understand correctly, you mean we should put the default value for |
@teohhanhui yep that's what I mean - and it looks like there is already a default value, so we could just remove these lines the yaml file: https://github.com/symfony/recipes/blob/3b19bd94886555df1997b441b6cf6a1fab088f3a/doctrine/doctrine-bundle/1.6/manifest.json PR welcome |
@nicolas-grekas to recap: the (updated) suggested way to setup in a Docker prod env is then:
Is that correct? |
It's only safe to use Edit: That seems to be correct based on the blog post. |
This change causes issues with Docker and other container systems (including for the API Platform distribution). Previously, it was possible to build the container without having environment variables set. A hack was already necessary, but it was a one easy to maintain: Now even this hack fails, and the workarounds aren't nice: The first one:
Here is the related diff in API Platform: api-platform/api-platform#1167 The other one, even uglier, is to generate the file manually:
|
Also, having things looking like secrets stored (even if they aren't production values) in the container will trigger warnings from many security systems. |
@dunglas as we discussed onSlack, this change in the recipe was a hack around the root issue, which is that the DATABASE_URL env var is read at build time. This should be fixed in DoctrineBundle I suppose. |
@dunglas I believe we should use |
@teohhanhui is does? symfony/flex#507 |
@Jean85 this is indeed still an issue: hitting it as
@nicolas-grekas
In a production system following 12FA principles (Dokku, Heroku, K8s, Swarm), @Jean85 I think the problem is more to the core: the application should not be bootstrapped to run things like |
You should use an empty value in
The |
Yes, I just clarified that this (the empty value) should not be put in For now, I'm working around the issue in key components of the application that need to run without environment by force-feeding variables where needed, such as in my
|
But the |
|
That was before https://symfony.com/doc/current/configuration/dot-env-changes.html |
Let me be more clear then: in applications (in general, not symfony), What symfony does is then certainly questionable (and I am questioning it). |
See the discussion in #28533, specifically #28533 (comment) (I was questioning the change too lol... But that's how things work now.) |
Yeah, in the current project I'm currently getting rid of The fact that symfony does also consider that file in I built up at least a dozen hours of work because of issues where docker (or a process) had an environment variable set, and that variable was then being replaced by |
Sounds like symfony/recipes#611 if you're talking about |
Two notes:
|
@Jean85, @Ocramius, I had the same issue with I can't explain why but if you explicitly tell Docker to load the missing vars. You will no more have empty values. DockerFile ARG APP_ENV
ARG MAILER_DSN docker-compose.yml services:
citadel:
build:
args:
ENV: 'prod'
APP_ENV: 'prod'
MAILER_DSN: ${MAILER_DSN} And now Might help other people to have a little hint it in the Exception message when building from a DockerFile ?. Keep up the good work ! 🚀 |
Thank you for this suggestion. |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
It seems to me that we still have to find consensus about the solution for this issue... |
Thank you for this suggestion. |
Could I get a reply or should I close this? |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Description
I'm hitting a constant issue while deploying my Symfony apps with Docker: during the Docker build I want to issue the cache:warmup command, and in that environment a lot of env variables are missing, because I'm not actually in the prod environment.
This forces me to define in the parameters a bunch of default values for env variables, so the container dump process will not complain about those. And those values are normally defaults or empty string.
I would like to suggest a new behavior: not complaining about missing env vars, at least during cache warmup: this would allow us to avoid defining all those variables as empty, and concentrate on having them just in the real prod environment.
Example
This could be done in some way like
bin/console cache:warmup --ignore-missing-envs
. WDYT?The text was updated successfully, but these errors were encountered: