dotnet-appsettings-env icon indicating copy to clipboard operation
dotnet-appsettings-env copied to clipboard

WARNING: Python-dotenv could not parse statement starting at line X

Open LQss11 opened this issue 3 years ago • 1 comments

Let's say I have an env file like this: docker.env

App__PathToFiles="C:\\Program Files\\SOMEPATH\\"
App__SomeOtherKey="Value"

and then passing it as an envfile in docker compose docker-compose.yaml

version: '3.3'
services:
  app:
    image: alpine
    container_name: app
    tty: true
    env_file:
      - ./docker.env

Running docker-compose up with that config produces this error:

WARNING: Python-dotenv could not parse statement starting at line 1

This is because bashlash telling env to ignore the double quote which will break the structure of the config.

LQss11 avatar Oct 21 '22 09:10 LQss11

Hi @LQss11, I believe it is due to the unnecessary double quotes in the variable value.

I tested it with the same content and it didn't work either.

% cat > appsettings.json <<EOF
{
    "App": {
        "PathToFiles": "C:\\\\Program Files\\\\SOMEPATH\\\\",
        "SomeOtherKey": "Value"
    }
}
EOF
% dotnet-appsettings-env-darwin-arm64 -type docker | tee docker.env
App__PathToFiles="C:\\Program Files\\SOMEPATH\\"
App__SomeOtherKey="Value"
$ cat > docker-compose.yml <<EOF
version: '3.3'
services:
  app:
    image: alpine
    container_name: app
    tty: true
    env_file:
      - ./docker.env
EOF
% docker-compose up
unexpected character "\"" in variable name near "Value\"\n"

Removing the double quotes worked as expected.

% dotnet-appsettings-env-darwin-arm64 -type docker | tr -d \" | tee docker.env
App__PathToFiles=C:\\Program Files\\SOMEPATH\\
App__SomeOtherKey=Value
% docker-compose up -d
[+] Running 2/2
 ⠿ Network x_default  Created                    0.0s
 ⠿ Container app      Started                    0.2s
% docker exec -it app ash
/ # env
HOSTNAME=e733b8d2435c
App__SomeOtherKey=Value
SHLVL=1
HOME=/root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
App__PathToFiles=C:\\Program Files\\SOMEPATH\\

Can you remove the double quotes from your docker.env file and see if it will work?

dassump avatar Oct 23 '22 00:10 dassump