-
-
Notifications
You must be signed in to change notification settings - Fork 496
Always load vars defined in .env files, providing .env.local.php for prod #501
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
@symfony/deciders votes welcome. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
(updated to use |
Things are getting really complicated IMHO. We have so many For example why do we need a committed .env file while we say that we need to defined a default value for each env var in the services.yaml ? (or another file). We need a default value for the default value ? But how many people really need really dynamic values ? very few. Symfony 4 + Flex + MakerBundle is really cool and easy. But theses env var really needed to be re-thought |
@lyrixx 💯 - that's what this PR provides :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
BTW, this PR is a very good move 👍 About this point (the part "which you should"):
I totally disagree. It's like always : it depend. Many applications are hosted on bare metal, and will not move. Using env var make things more complicated because you need to load them for FPM + CLI + CRON + Worker. Using a simple So we should not say :
Declaring parameter in |
👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request passes validation.
@nicolas-grekas This PR probably causes PHPUnit to fail:
Steps to reproduce:
|
Nevermind, just found #512 |
…loaded (weaverryan) This PR was merged into the 4.1 branch. Discussion ---------- Documenting changes recipe 501 - where .env is always loaded See symfony/recipes#501 This basically documents *part* of what is included in #10793. That PR also documents the Flex `composer sync-recipes --force` and `composer dump-env prod` commands, neither of which exist yet. When those are merged / tagged, I'll finish that PR. Note: after merging to 4.2, the URLs at the bottom of `dot-env-changes` need to be changed to point to the 4.2 recipes. Thanks! Commits ------- 203d93a Documenting changes recipe 501 - where .env is always loaded
That's a good point and I also see a duplication in here. From the documentation (https://symfony.com/doc/current/configuration/external_parameters.html):
# config/services.yaml
parameters:
env(DATABASE_HOST): localhost By default, the kernel loads the |
A For instance, check the Recaptcha recipe: Google credentials are mandatory, but they won't break the app if they're not valid. They will break only the portions that actually use a captcha. |
…al.php (nicolas-grekas, renanbr) This PR was merged into the 1.2-dev branch. Discussion ---------- Add "dump-env" command to compile .env files to .env.local.php This adds a new command that compiles .env files to .env.local.php: ``` $ composer dump-env prod Successfully dumped .env files in .env.local.php ``` The generated file is used in symfony/recipes#501 Commits ------- 7e561d5 add --empty option 31b12b1 Add "dump-env" command to compile .env files to .env.local.php
Looks like according to these changes: symfony/recipes#501 - Dotenv component is suggested to be added to `require` section of `composer.json`. Both `symfony/skeleton` and `symfony/website-skeleton` require it on prod
This PR was merged into the 3.4 branch. Discussion ---------- Require Dotenv component without --dev Looks like according to these changes: symfony/recipes#501 - Dotenv component is suggested to be added to `require` section of `composer.json`. Both `symfony/skeleton` and `symfony/website-skeleton` require it on prod Commits ------- 3f7594d Require Dotenv component without --dev
…s logic (cristi-contiu) This PR was submitted for the 4.1 branch but it was merged into the 4.4 branch instead. Discussion ---------- [Deployment] Update deployment docs with new .env files logic The [changes from last year regarding how the ``.env`` files are loaded](https://symfony.com/doc/current/configuration/dot-env-changes.html) can affect production deployments. Vendors like [Heroku](https://devcenter.heroku.com/articles/deploying-symfony4#environment-variables) give recommendations based on documentation that no longer applies: "It is recommended that you do not use the symfony/dotenv package in production". The ``symfony/dotenv`` has been moved from ``require-dev`` to ``require``, so the note I removed in this PR no longer applies: symfony/skeleton#122 , symfony/website-skeleton#132 and symfony/demo@7ead1e4 . Loading ``.env`` files in production will work without any changes in composer.json. Putting ``symfony/dotenv`` in ``require-dev`` (or not moving it to ``require`` during an upgrade from older versions of Symfony & recipes) can potentially break your app: if the DotEnv class is missing, the [`config/bootstrap.php` file inside the FrameworkBundle's recipe will throw a RuntimeException](https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/3.3/config/bootstrap.php#L14) . Also see symfony/recipes#501 The note now contains the right way to handle these files in production, by using ``$ composer dump-env prod`` in case you do not want the ``.env`` files to be processed on every request, also suggesting the ``--empty`` flag if you want to rely exclusively on "real" environment variables . Commits ------- b905b57 Update deployment docs with new .env loading
This PR provides a nice experience where
.env
files are "always" loaded.That means their purpose is easy to reason about: the committed files define the defaults (
.env
especially) - and.env.local
defines local overrides.A new
.env.local.php
is provided for prod, so that performance is not affected.When
.env.local.php
is found, other .env files are ignored.On the deployement side, this means it should be much easier to deal with
.env
files for people that can't easilly deal with real env vars:.env
files are always loaded (to define defaults).env.local.php
file for max performanceThe plan is to add a new flex command to create this file and ease deployments:
composer dump-env prod