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

CRLF line endings in .env file break warden env up #380

Closed
navarr opened this issue May 29, 2021 · 4 comments · Fixed by #381
Closed

CRLF line endings in .env file break warden env up #380

navarr opened this issue May 29, 2021 · 4 comments · Fixed by #381
Labels
bug Something isn't working

Comments

@navarr
Copy link
Member

navarr commented May 29, 2021

navarr@Bulbasaur:/e/PhpstormProjects/dependency-annotation$ warden env up
" specified.ronment type "laravel

System: Ubuntu WSL2 on Windows 10, Docker Desktop setup for WSL2.

.env:

WARDEN_ENV_NAME=depends
WARDEN_ENV_TYPE=laravel
WARDEN_WEB_ROOT=/

TRAEFIK_DOMAIN=depends.test
TRAEFIK_SUBDOMAIN=app

WARDEN_PHP=1
PHP_VERSION=7.4

COMPOSER_VERSION=2
WARDEN_COMPOSER_DIR=./.composer

Not really sure what's going on here. I have another environment with WARDEN_ENV_TYPE=laravel that launches fine:

WARDEN_ENV_NAME=grakkus
WARDEN_ENV_TYPE=laravel
WARDEN_WEB_ROOT=/webroot

TRAEFIK_DOMAIN=grakkus.test
TRAEFIK_SUBDOMAIN=app

WARDEN_NGINX=1
WARDEN_DB=1
WARDEN_REDIS=1
WARDEN_PHP=1

PHP_VERSION=7.4

MYSQL_DATABASE=grakkus
MYSQL_ROOT_PASSWORD=grakkus
MYSQL_USER=grakkus
MYSQL_PASSWORD=grakkus

Warden 0.11.0:

navarr@Bulbasaur:/opt/warden$ git status
HEAD detached at 0.11.0
nothing to commit, working tree clean
@tdgroot
Copy link
Contributor

tdgroot commented May 30, 2021

@navarr this problem looks familiar to me. I encountered this issue when I was generating .env files incorrectly. What was incorrect at that time was that I quoted every value by default. Warden didn't seem to like that.

You config file looks fine to me. Perhaps the file has Windows line endings?

@navarr
Copy link
Member Author

navarr commented May 31, 2021

@tdgroot You got it in one, thanks!

Working every day in Mac, it stopped being something I'd even consider having to think about. Appreciate it!

@navarr navarr closed this as completed May 31, 2021
@davidalger
Copy link
Collaborator

I can easily reproduce this by changing line endings from LF to CRLF:

davidalger@silver-bullet:~/Sites/m2sandbox (develop) $ cat .env | perl -pe "s/\n$/\r\n/g" > .env-cr; mv .env-cr .env
davidalger@silver-bullet:~/Sites/m2sandbox (develop *) $ warden env ps
" specified.ronment type "magento2

Would it be worth it perhaps to update loadEnvConfig (https://github.com/davidalger/warden/blob/develop/utils/env.sh#L34-L57) to instead do the following:

    eval "$(cat "${WARDEN_ENV_PATH}/.env" | sed 's/\r$//g' | grep "^WARDEN_")"
    eval "$(cat "${WARDEN_ENV_PATH}/.env" | sed 's/\r$//g' | grep "^TRAEFIK_")"
    eval "$(cat "${WARDEN_ENV_PATH}/.env" | sed 's/\r$//g' | grep "^PHP_")"

Sed removes the trailing '\n' when it parses for matching, hence the use of \r$ to match the CRLF, removing the \r before grepping. Thoughts?

@davidalger davidalger changed the title Cannot run local environment on Windows CRLF line endings in .env file break warden env up Jun 2, 2021
@davidalger davidalger reopened this Jun 2, 2021
@davidalger davidalger added the bug Something isn't working label Jun 2, 2021
@navarr
Copy link
Member Author

navarr commented Jun 2, 2021

It'd certainly be a nice UX tweak to prevent issues like this that someone may not notice or think to look at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants