From bc30b3fc002dedb1a8986c30f97ccb8f6a442495 Mon Sep 17 00:00:00 2001 From: Carlos H Brandt <carloshenriquebrandt@gmail.com> Date: Tue, 16 Apr 2019 23:24:09 +0200 Subject: [PATCH] Dachs discovers the name of linked Postgres host/container Before, Postgres container should be named 'postgres' to make the connection work, now Dachs figures out the name of it from container's environment variable. Needless to say the --link (legacy link) is still mandatory. TODO: move legacy-link to use (virtual) network. --- dockerfile/bin/dachs.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/dockerfile/bin/dachs.sh b/dockerfile/bin/dachs.sh index 3f563d1..72c5f78 100755 --- a/dockerfile/bin/dachs.sh +++ b/dockerfile/bin/dachs.sh @@ -2,30 +2,34 @@ echo '' echo '================================================' -echo 'This the (main) DaCHS server container, where' -echo 'DaCHS daemon is meant to run.' -echo 'This container expects to use another container' -echo 'as the PostgreSQL databse server.' +echo 'This is the DaCHS server container,' +echo 'where DaCHS daemon runs.' echo '' -echo 'The Postgres container must be named *postgres*.' -echo 'Using the proper name will make the connection' -echo '"just work".' +echo 'This container expects to use another container' +echo 'as the PostgreSQL database server.' +echo 'This "expectation" is satisfied with Docker' +echo 'option --link <name-of-postgres-container>.' echo '' -echo 'Apart from that restriction, DaCHS management' -echo 'proceed as usual (imp, pub, etc.).' +echo 'If something doesnt work as expected, issue-us:' +echo '- https://github.com/chbrandt/docker-dachs' echo '================================================' echo '' +# get the name of the postgres container linked to this one +PG_ENV_ALIAS=$(env | grep "ENV_PG_VERSION" | cut -d"_" -f1) +PG_HOST=$(basename `env | grep "${PG_ENV_ALIAS}_NAME" | cut -d"=" -f2`) +export PG_HOST + # first, make sure the environment is initialised (can't do that # at image build time since the postgres container is not available then) echo -n "Waiting for postgres to come up..." -while ! su - dachsroot -c "psql -h postgres --quiet gavo -c 'SELECT 1' > /dev/null 2>&1" ; +while ! su - dachsroot -c "psql -h ${PG_HOST} --quiet gavo -c 'SELECT 1' > /dev/null 2>&1" ; do sleep 5 echo -n . done echo -su dachsroot -c "gavo init -d 'host=postgres dbname=gavo'" +su dachsroot -c "gavo init -d 'host=${PG_HOST} dbname=gavo'" gavo serve start -- GitLab