[Bug]: The .env file from the repository is being overwritten by the project's environment parameters.
Description
Hello.
I have a .env file in the repository, but I've noticed that it's being overwritten by the project's environment parameters.
How can I avoid this?
Minimal Reproduction (if possible, example repository)
- Place the .env file in the root directory of the repository with some parameters.
- Use these parameters in the application.
Exception or Error
Symfony\Component\DependencyInjection\Exception\EnvNotFoundException: Environment variable not found: "ENABLE_PAYMENTS".
Version
v4.0.0-beta.259
It's not good practice to commit a .env file... I would guess that this functionality is intended
@ashermyers Thanks for the answer.
It was working before, about 1 week ago.
Normally, the .env file keeps default values, while .env.local and OS environments should override them. It's a common practice. (I'm sure you know it)
I think overriding the entire app file instead of extending it isn't how it should work. Maybe in this case, Coolify should throw an exception like "Unexpected file" or at leas warning message.
P.S. Where should default values be stored instead?
Okay gotcha.. That makes a lot more sense. I thought you were trying to load secrets from a github repository of some sorts...
The new version will respect the .env file, but any environment variables defined in Coolify will overwrite the values.
I reverted it for now in v264, because it caused issues for some people.
I reverted it for now in v264, because it caused issues for some people.
Hi, when there will be a workaround, so the .env variables won't be overridden?
Deleting of .env caused critical bugs to my projects few times in a row :(
What are the best practice for the workaround till it is not fixed?
Normally, the .env file keeps default values, while .env.local and OS environments should override them. It's a common practice.
It is definitely not:
It is added to each project but NOT committed to source control.
https://www.dotenv.org/docs/security/env
If you want to distribute examples to your devs, please use a file like env.example. This is the way a lot of projects solve this
@codesalatdev
Thanks for clarifying. Common practice ≠ best practice. Now I see that it is even a common mistake to push the .env file.
In the .env file, I store default values like "ENABLE_PAYMENTS", which has no sensitive info.
@VCasecnikovs Quick workaround: moving envs inside the Environment Variables section.
That's what I did.
@VCasecnikovs Quick workaround: moving envs inside the Environment Variables section.
That's what I did. Do you mean Coolify's environent variable for resource section?
@VCasecnikovs Quick workaround: moving envs inside the Environment Variables section. That's what I did. Do you mean Coolify's environent variable for resource section?
I mean to put .env variables here.
Sorry, wrong printscreen. Was thinking about the same, thank you As an alternative adding .env.local file.
Not sure if you're using dotenv-flow or not. But if yes, then you can commit .env.defaults to th repo and it will use that file for fallback values (instead of .env)
