Skip to content

[Dotenv] Reimplementing symfony/flex' dump-env as a Symfony command #42610

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

Merged
merged 2 commits into from
Sep 30, 2021

Conversation

abdielcs
Copy link
Contributor

@abdielcs abdielcs commented Aug 17, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #40381
License MIT
Doc PR -

[FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command. Most of code copied from https://github.com/symfony/flex/blob/main/src/Command/DumpEnvCommand.php

The command is not registered by default. In order to enable it, one must add it to their services.yaml file:

services:
    Symfony\Component\Dotenv\Command\DotenvDumpCommand:
        - '%kernel.project_dir%/.env'
        - '%kernel.environment%'

On PHP >= 8, the two arguments can be removed when autoconfiguration is enabled (which is the default):

services:
    Symfony\Component\Dotenv\Command\DotenvDumpCommand: ~

Copy link
Contributor

@t-richard t-richard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its also missing tests. See https://github.com/symfony/flex/blob/main/tests/Command/DumpEnvCommandTest.php

Otherwise I'm 👍, it also proved to be sub-optimal for me to have it as a composer plugin command rather than a symfony command.

It would be great if you were also able to submit a PR to https://github.com/symfony/flex for the deprecation of the the command.

@nicolas-grekas nicolas-grekas added this to the 5.4 milestone Aug 18, 2021
@abdielcs
Copy link
Contributor Author

Help with this issues please? unset($_ENV['SYMFONY_DOTENV_VARS']) came from original code in https://github.com/symfony/flex/blob/main/src/Command/DumpEnvCommand.php and need to be done to pass tests, and Psalm insists that is not set. Not sure what need to be done to rebase upstream. Seems also a test is failing from HttpKernel.

@ro0NL
Copy link
Contributor

ro0NL commented Aug 19, 2021

See vimeo/psalm#6337

@nicolas-grekas nicolas-grekas changed the title [FrameworkBundle] feature #40381 Reimplementing the symfony/flex env-dump as a symfony command. [FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command. Sep 8, 2021
@nicolas-grekas
Copy link
Member

Please rebase and squash also (PR should not contain any merge commits)

@derrabus derrabus changed the title [FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command. [FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command Sep 8, 2021
@derrabus derrabus added the Dotenv label Sep 8, 2021
@carsonbot carsonbot changed the title [FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command [Dotenv][FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command Sep 8, 2021
@nicolas-grekas
Copy link
Member

We might need to implement symfony/flex#810 in this also.
@abdielcs are you still available to finish this PR?

@abdielcs
Copy link
Contributor Author

We might need to implement symfony/flex#810 in this also.
@abdielcs are you still available to finish this PR?

@nicolas-grekas Al the work is done, but I can't managed to pass the rebase. Really would appreciate help here. Sorry for been so newbie doing PR.

@nicolas-grekas nicolas-grekas changed the title [Dotenv][FrameworkBundle] Reimplementing the symfony/flex env-dump as a symfony command [Dotenv][FrameworkBundle] Reimplementing symfony/flex' dump-env as a Symfony command Sep 27, 2021
@nicolas-grekas
Copy link
Member

@abdielcs I rebased the PR and pushed it on your fork. Please fetch and sync your local copy before moving the command to the component.

@carsonbot carsonbot changed the title [Dotenv][FrameworkBundle] Reimplementing symfony/flex' dump-env as a Symfony command [Dotenv] Reimplementing symfony/flex' dump-env as a Symfony command Sep 30, 2021
@nicolas-grekas nicolas-grekas force-pushed the 5.4 branch 2 times, most recently from ea949b4 to e15b003 Compare September 30, 2021 10:03
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased the PR and added a second commit to completly decouple the command from FrameworkBundle.

@abdielcs I saw that you somehow messed up with the git history in previous iterations. As a general rule of thumb, do never ever use git merge when working on PRs for open-source projects. Use git rebase instead.

@nicolas-grekas
Copy link
Member

Thank you @abdielcs.

@mbrodala
Copy link
Contributor

Awesome thanks a lot!

This was referenced Nov 5, 2021
leofeyer pushed a commit to contao/contao that referenced this pull request Feb 29, 2024
…dition (see #6954)

Description
-----------

We know that Contao is mostly deployed on hosting providers that do not support real environment variables but we also rely on the `Dotenv` component ourselves for e.g. Mailer configuration etc.

For performance reasons, on those systems I would like to run `dotenv:dump` so Symfony dumps `.env.local.php` which is way faster as it can be cached in OPCode cache. Of course, you cannot change `.env.local` anymore without also updating that file then. But you will have to add `dotenv:dump` to your deploy chain manually anyway so you'll know that - it doesn't happen just like that.

However, the command is not registered by default in Symfony even though it has been around since Symfony 5.4. See symfony/symfony#42610. This means that right now I have to add this configuration to every ME but given the fact of our hosting provider situation, I think this qualifies to be a good default.
Again, it just makes sure the command is around, you'll still have to use it yourself.

Commits
-------

5f18133 Register the dotenv:dump command by default in the Contao ME
11337ab Adjust service name
f236946 Update manager-bundle/config/services.yaml
leofeyer pushed a commit to contao/manager-bundle that referenced this pull request Feb 29, 2024
…dition (see #6954)

Description
-----------

We know that Contao is mostly deployed on hosting providers that do not support real environment variables but we also rely on the `Dotenv` component ourselves for e.g. Mailer configuration etc.

For performance reasons, on those systems I would like to run `dotenv:dump` so Symfony dumps `.env.local.php` which is way faster as it can be cached in OPCode cache. Of course, you cannot change `.env.local` anymore without also updating that file then. But you will have to add `dotenv:dump` to your deploy chain manually anyway so you'll know that - it doesn't happen just like that.

However, the command is not registered by default in Symfony even though it has been around since Symfony 5.4. See symfony/symfony#42610. This means that right now I have to add this configuration to every ME but given the fact of our hosting provider situation, I think this qualifies to be a good default.
Again, it just makes sure the command is around, you'll still have to use it yourself.

Commits
-------

5f181332 Register the dotenv:dump command by default in the Contao ME
11337abd Adjust service name
f236946e Update manager-bundle/config/services.yaml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide "dump-env" as regular Symfony command
8 participants