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

[Bug]: .env file is not written correctly when variable value contains a space #2397

Closed
victorlap opened this issue Jun 8, 2024 · 11 comments · Fixed by #3425
Closed

[Bug]: .env file is not written correctly when variable value contains a space #2397

victorlap opened this issue Jun 8, 2024 · 11 comments · Fixed by #3425

Comments

@victorlap
Copy link
Contributor

Description

I was trying to deploy a laravel application, and for the APP_NAME variable I have a string with a space.

Apparently coolify doesn't handle this well, since it doesn't escape this in the .env file that is written. vlucas/phpdotenv crashes when it sees an unescaped value with whitespaces.

Minimal Reproduction (if possible, example repository)

Create new coolify project using example repo: https://github.com/victorlap/coolify-env-repro
Set build to Dockerfile
Add environment variable with space in value
Try to deploy

Exception or Error

I see the following error:

26.57 Failed to parse dotenv file. Encountered unexpected whitespace at [My String].

I tried quoting the value myself, but then the quotes get escaped:

28.97 Failed to parse dotenv file. Encountered unexpected whitespace at [\"My String\"].

Version

v4.0.0-beta.294

@victorlap
Copy link
Contributor Author

I found a workaround by adding the quotes myself and selecting 'is literal'.

I do think that it would be nice if this works out of the box though.

@iFlyinq
Copy link

iFlyinq commented Jun 14, 2024

I found a workaround by adding the quotes myself and selecting 'is literal'.

I do think that it would be nice if this works out of the box though.

Encountering this one as well, but the trick you suggest doesn't seem to fix it.

@JuanxCursed
Copy link
Contributor

I found a workaround by adding the quotes myself and selecting 'is literal'.

I do think that it would be nice if this works out of the box though.

That made the trick to me

@ZackBz
Copy link

ZackBz commented Aug 29, 2024

I found a workaround by adding the quotes myself and selecting 'is literal'.
I do think that it would be nice if this works out of the box though.

Encountering this one as well, but the trick you suggest doesn't seem to fix it.

I just tried this as i was facing the same issue in my app and it did work. Make sure to enter the variable in double quotes and check 'is literal' as @victorlap suggested. Also don't forget to save, and redeploy/restart.

Example image

@JuanxCursed
Copy link
Contributor

JuanxCursed commented Sep 4, 2024

It started happening again on version v4.0.0-beta.325

[2024-Sep-04 01:16:49.633208] failed to read /artifacts/t8s0g0wkc0kko0oswwcookog/.env: line 6: unexpected character "/" in variable name

The weird part is that there isn't a / character on this variable (both on generated .env at the server or my own env lines)

@JuanxCursed
Copy link
Contributor

I've deleted all my env variables, but I'm still getting the "same error"

GTM_ID=
NUXT_PUBLIC_METAPIXEL_DEFAULT_ID=

I noticed that the error changed when I changed the resource name as well, Leads / Anamnese to Leads

[2024-Sep-04 01:36:45.721585] failed to read /artifacts/x0c080sowcwsws4wwowso4gk/.env: line 6: key cannot contain a space

@AndreVarandas
Copy link

In my case (laravel app) it was picking up the Project Name as the APP_NAME.
Overriding it in the environment variables didn't work. I had to rename the project and it worked right away.

@Sillyvan
Copy link

Sillyvan commented Sep 9, 2024

In my case (laravel app) it was picking up the Project Name as the APP_NAME. Overriding it in the environment variables didn't work. I had to rename the project and it worked right away.

Just ran into the same issue!

@saullo
Copy link

saullo commented Sep 9, 2024

In my case (laravel app) it was picking up the Project Name as the APP_NAME. Overriding it in the environment variables didn't work. I had to rename the project and it worked right away.

I lost a lot of time at work because of this same problem...

@ktufekcic
Copy link

I've been encountering a very different problem but possibly related. When Coolify adds the .env file, it also adds some of it's own env vars, most relevant here being COOLIFY_APP_NAME, which corresponds to the name you gave to your resource, and if this has spaces, it will always include them in the .env file, and the only fix (that I could come up with) is to just not have spaces in any resource names

@andrasbacsai
Copy link
Member

I've been encountering a very different problem but possibly related. When Coolify adds the .env file, it also adds some of it's own env vars, most relevant here being COOLIFY_APP_NAME, which corresponds to the name you gave to your resource, and if this has spaces, it will always include them in the .env file, and the only fix (that I could come up with) is to just not have spaces in any resource names

This will be fixed in the upcoming version.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants