Skip to content
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

Look for a .env.local for specific overrides. #586

Closed
wants to merge 2 commits into from

Conversation

trsteel88
Copy link

This is a different approach to override ENV variables (one that the Symfony framework follows).

Rather than executing a script from composer.json, .env becomes the default (and is committed).

Then, if you want to override specific variables, you would create a .env.local on the relevant environment. The .env.local is not committed.

This also solves an issue where ENV variables don't exist. e.g. if a dev creates a new ENV variable in .env.example. This isn't automatically appended to any other developers .env variables.

If they were to commit .env with a suitable default, then any other developers using the codebase will automatically use the suitable default defined.

@swalkinshaw
Copy link
Member

🤔 I like parts of this idea.

Though overall I find it a bit weird to have a .env file committed with useless values. They aren't useful defaults, they're placeholders that have to be replaced. Usually the config model of having a .local override is for actual overrides.

@austinpray what do you think

@JulienMelissas
Copy link
Contributor

JulienMelissas commented Apr 8, 2021

👍 to having a local override option, 👎 to committing the .env... that seems like a violation of best practices IMO.

@MWDelaney
Copy link
Member

.env is a build artifact. We shouldn't commit it.

@trsteel88
Copy link
Author

I wouldn't say they are useless defaults. The idea would be that you would put useful defaults in there and then if something needed to be reconfigured you would add it to the .env.local

I find it strange that .env.example is automatically copied to .env during a composer install.

If a developer creates a new ENV var then anyone who already has the project setup won't automatically get these variables which could then cause an exception in the application.

@tangrufus
Copy link
Member

I vote for following vlucas/phpdotenv's expected usage plus allowing .env.local to override Trellis generated .env, i.e:

  • keep .env git ignored
  • keep .env.example
  • remove

    bedrock/composer.json

    Lines 62 to 63 in 3dbfaec

    "post-root-package-install": [
    "php -r \"copy('.env.example', '.env');\""
  • load .env.local if exist
    - $dotenv = Dotenv\Dotenv::createUnsafeImmutable($root_dir);
    + $dotenv = Dotenv\Dotenv::createUnsafeImmutable($root_dir, ['.env', '.env.local'], false);

Use case:
Overriding DB credentials when using valet, local DB and $ trellis dotenv. So that my teammates are not required to follow my db_password.

@trsteel88
Copy link
Author

Here is another solution: #587

Don't commit .env and just load .env.example first. If .env exists it will override project defaults.

@swalkinshaw
Copy link
Member

@trsteel88 thanks for proposing this and getting us thinking. #595 and #594 are the changes that will come out of all this discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants