docker-taiga / taiga

docker-compose.yml for simple taiga setup
215 stars 75 forks source link

could not translate host name "$POSTGRES_HOST" to address: Name does not resolve #41

Closed tacticz closed 2 years ago

tacticz commented 3 years ago

Hello,

Not sure whether I should post here or rather under "docker-taiga/back" since the issue seems to be Django related, but it seems posting here makes more sense as a "centralized" issue reports point.

Trying to deploy docker-taiga on my workstation, I configured the variable.env file in the simplest possible way, i.e. just specifying TAIGA_HOST, TAIGA_SECRET, POSTGRES_PASSWORD, RABBIT_PASSWORD and REDIS_PASSWORD values, leaving all other ones to their defaults.

Running docker-compose up starts all the expected containers but, in the outputted logs, the following error is reported: django.db.utils.OperationalError: could not translate host name "$POSTGRES_HOST" to address: Name does not resolve

Connecting to the taiga-back container, using docker exec -it taiga-back /bin/sh, showed that the environment variable was well set and that the db hostname was well recognized inside the container:

$ docker exec -it taiga-back /bin/sh
srv/taiga/back # echo ${POSTGRES_HOST}
db
srv/taiga/back # ping -c 3 ${POSTGRES_HOST}
PING db (172.24.0.4): 56 data bytes
64 bytes from 172.24.0.4: seq=0 ttl=64 time=0.184 ms
64 bytes from 172.24.0.4: seq=1 ttl=64 time=0.164 ms
64 bytes from 172.24.0.4: seq=2 ttl=64 time=0.162 ms

--- db ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.162/0.170/0.184 ms

Looking at the settings/local.py file one can see that Django's DATABASES settings are indeed set as follow:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": "$POSTGRES_DB",
        "HOST": "$POSTGRES_HOST",
        "USER": "$POSTGRES_USER",
        "PASSWORD": "$POSTGRES_PASSWORD"
    }
}

Not having enough experience with Django, I only can suspect that the $NAMES values do not get substituted with their equivalent environment variables values. But I wonder why this seems to be working for other users and not for me (since I didn't find someone reporting this problem in previous issues).

Thank you very much for any hint that could lead me to a working solution.

tacticz commented 3 years ago

Digging into the problem here is what I found out:

both /srv/taiga/back/settings/local.py and /srv/taiga/back/settings/celery.py files are symlinks to the identically named files located under /taiga-conf/, which itself is the docker mounted persistent volume under ./conf/back. Interestingly enough, the celery.py file present in that same directory has all $ENV_VAR names correctly substituted.

Both of these files are generated by the start.sh script when it runs at first launch. The generation process is using the sed command to substitute values present in the template /tmp/taiga-conf/config.py and /tmp/taiga-conf/celery.py files. What I observed, by manually running both sed commands present in the start.sh script, is that an error is returned when executing it on the /tmp/taiga-conf/config.py:

/tmp/taiga-conf # sed -e 's/$TAIGA_HOST/'$TAIGA_HOST'/' \
-e 's/$TAIGA_PORT/'$TAIGA_PORT'/' \
-e 's/$TAIGA_SECRET/'$TAIGA_SECRET'/' \
-e 's/$TAIGA_SCHEME/'$TAIGA_SCHEME'/' \
-e 's/$POSTGRES_HOST/'$POSTGRES_HOST'/' \
-e 's/$POSTGRES_DB/'$POSTGRES_DB'/' \
-e 's/$POSTGRES_USER/'$POSTGRES_USER'/' \
-e 's/$POSTGRES_PASSWORD/'$POSTGRES_PASSWORD'/' \
-e 's/$RABBIT_HOST/'$RABBIT_HOST'/' \
-e 's/$RABBIT_PORT/'$RABBIT_PORT'/' \
-e 's/$RABBIT_USER/'$RABBIT_USER'/' \
-e 's/$RABBIT_PASSWORD/'$RABBIT_PASSWORD'/' \
-e 's/$RABBIT_VHOST/'$RABBIT_VHOST'/' \
-i /tmp/taiga-conf/config.py
sed: bad option in substitution expression

Manually running each substitution line by line revealed that the problem occurred when substituting the value for TAIGA_SECRET, which indeed contains special characters that are braking the sed command execution (i.e. ; & # / , $ and _). I didn't yet tried to figure out which one(s) are problematic Surrounding the TAIGA_SECRET value definition with quotation marks in the variables.env file makes it work but doesn't completely fix the problem since the surrounding quotation marks are then part of the secret value itself.

I keep digging the situation, as the obvious solution is NOT to use special characters in the secret, and haven't either defined yet whether a similar problem might exist with the xxx_PASSWORD values...

In the meantime any relevant information regarding a way the sed command in the start.sh script could be adapted to work with special characters would be welcome!

Thank you.

w1ck3dg0ph3r commented 3 years ago

Hello! Thanks a lot for digging into this! I'll try to fix this shortly and come back with an update.

w1ck3dg0ph3r commented 3 years ago

Should be fixed for now in https://github.com/docker-taiga/back/commit/7a0e0d580c89971876888969d5292f9aa1a9c059 and https://github.com/docker-taiga/events/commit/36ac3c61e41cf4b497bde09c3abe10d409124b2f, but I may have missed something. Nevertheless, may be a better long term solution would be to use a different tool for writing/managing configs.