-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DX] Flaws in the way environment variable are used ? #27962
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
If you have your env vars in To fix it, you either have a wrapper which does, or, more simply, source |
I don’t have my environement in a |
I think you are trying to find a good solution for a bad practice, your actual project should be isolated from others projects. Also I think you should avoid to use env. vars in that scenario because you have the risk of write dev data into prod or in the other way around. The solutions that I think you can take is...
|
I totally agree with @tristanbes. For me, it's really hard to handle env vars at so many places (6):
When running PhpUnit and Behat inside Travis, I should either manually define env vars from Travis UI, or use a copy of Docker might be the ideal solution to isolate Symfony apps (and any other apps BTW), but as said before, I don't want to learn nor masterize Docker for something that should be so simple to manage. At the moment, I followed those steps to make my life easier:
I'm feeling dirty, but it works, and that's easier to maintain/use for me. Personally, I found paremeters so much useful and easier...
and that works! |
@Kocal and you can still use a parameters.yml file. My own approach is actually a mix of both. As I'm deploying on Heroku, I'm using |
Oh, that's interesting, I wasn't aware about that. I will try to find some time for migrating to |
It also solves 2000 other problems... Not to derail the discussion or anything but treating Docker as a solution for this issue you're having is like saying the best thing about a car is that you're dry inside. Docker solves nearly every deployment and testing issue. Elegantly and reliably. |
and creates 3000 others problems. (PS: we provision & deploy our applications using Ansible playbooks, so I don't think our infrastructure is like FTP ages.) |
@curry684 I think learn Docker now is a bit like learn Symfony 3.1 today... Anyway he is not asking for improve his archicture side, so I'll shut up. |
I don't think introducing Docker into this conversation solves anything.
"server that hosts multiple apps" doesn't imply "server that hosts multiple apps using the same account", that makes a significant difference. Doing so is hardly recommended. Having said that, I understand there are various situations in which you'd want to to that, when you might not have the choice to do it better. The question is all about understanding how env vars inheritance works and scoping:
You can handle it yourself
If you're using Ansible as you've noted before, setting this up and distributing the env vars everywhere should be very simple to do. |
Somehow related / my take on this: symfony/flex#287 Please note that the biggest issue with using a My workflow is using |
Issue symfony/flex#251 is closely related to this one. |
IMO we need to improve the documentation to make it more clear when there is actual value to use environment variables and when you should rather stick with well-known container parameters. Right now we lack to make clear that there is nothing wrong in still using them, but we seems to confuse (too) many developers right now. From what I have seen in different projects and on Slack is that people overcomplicate their setup and deployment process by using environment variables when plain old container parameters would have solved their problems way easier. |
@xabbuh If I understand well, we should not use env vars (in Well, it seems logical just by writing it... and it's even written in the doc:
Also, if we really need to defines env vars but without a parameters:
env(FOO): value |
Don't you use FPM with different pools? (Which also seperates the user processes) You can (and should) define the ENV vars directly in the pool config. Like:
|
I personally load projects env vars via |
@chalasr so you have one *nix user per project? |
@Kocal yes, one project per host and one |
And how do you handle env vars through web server? You still have to duplicate them right? |
Indeed, an additional env file per FPM pool. Env vars are managed in a vault (single place) and dumped for both CLI and FPM on deploy (via Ansible) |
@chalasr why dont you include a own file in your fpm pool?
fpm.conf looks llike:
This file can be deployed via ansible, you need to restart the fpm - but you should anyway after deployment to reset the op cache. But unfortunatly this does'nt solve the problem to get the env vars into CLI (eg. for bin/console) |
Closing as this improved a lot recently, with symfony/recipes#501 as the last step. |
One solution for docker in entry point |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
After a discussion on Symfony Slack about environment variables and CLI around my question:
It seems that nothing solid came out out of this discussion.
The documentation states that environment variables should be added on the webserver level on production.
Nothing is said reguarding the
CLI
, so a lot of people (like me) will end up spending time looking for why a crontab entries is not executed.To me, prefixing the executed commands by the environment variables is not a good solution. I mean, it would involve:
Regarding of this, why push in favor of environement variable if the only way of achieving this is to use a not recommended way (
.env
file).One alternate solution would be to create a file on the system in
/etc/environment
that contains those environment variable, BUT again, what happens if your server hosts multiple projects and you want one app X to beAPP_ENV=prod
and the other YAPP_ENV=dev
, then you have a variable collusion with the name unless you change theAPP_ENV
variable name in all project to include a vendor prefix ? (I don't even know if it's feasible).Not all of us use containers to run in production (or doesn't even want to).
PS: I open this here instead of the documentation repository because it reveals more questions than just "how to deal with that in doc is missing".
The text was updated successfully, but these errors were encountered: