coolify icon indicating copy to clipboard operation
coolify copied to clipboard

[Bug]: The .env file from the repository is being overwritten by the project's environment parameters.

Open victorshdev opened this issue 1 year ago • 15 comments

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)

  1. Place the .env file in the root directory of the repository with some parameters.
  2. 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

victorshdev avatar Apr 16 '24 11:04 victorshdev

It's not good practice to commit a .env file... I would guess that this functionality is intended

ashermyers avatar Apr 16 '24 13:04 ashermyers

@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?

victorshdev avatar Apr 16 '24 13:04 victorshdev

Okay gotcha.. That makes a lot more sense. I thought you were trying to load secrets from a github repository of some sorts...

ashermyers avatar Apr 16 '24 13:04 ashermyers

The new version will respect the .env file, but any environment variables defined in Coolify will overwrite the values.

andrasbacsai avatar Apr 17 '24 09:04 andrasbacsai

I reverted it for now in v264, because it caused issues for some people.

andrasbacsai avatar Apr 18 '24 05:04 andrasbacsai

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 :(

VCasecnikovs avatar May 15 '24 08:05 VCasecnikovs

What are the best practice for the workaround till it is not fixed?

VCasecnikovs avatar May 15 '24 09:05 VCasecnikovs

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 avatar May 15 '24 13:05 codesalatdev

@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.

victorshdev avatar May 15 '24 15:05 victorshdev

@VCasecnikovs Quick workaround: moving envs inside the Environment Variables section.

That's what I did.

victorshdev avatar May 15 '24 15:05 victorshdev

@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 avatar May 15 '24 15:05 VCasecnikovs

@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?

Screenshot 2024-05-15 at 12 24 32

I mean to put .env variables here.

Screenshot 2024-05-15 at 17 58 06

victorshdev avatar May 15 '24 15:05 victorshdev

Sorry, wrong printscreen. Was thinking about the same, thank you As an alternative adding .env.local file.

VCasecnikovs avatar May 15 '24 16:05 VCasecnikovs

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)

simontong avatar Jul 12 '24 23:07 simontong