From f8fdc83b4a4bd4afe9e1690a0e4c2c24114194c1 Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Wed, 28 Sep 2016 22:33:01 +0100 Subject: [PATCH] Made DB port configurable from DB_HOST env variable This ensures the database port is configurable whilst having the same configration syntax as the BookStack .env options. As per ssddanbrown/BookStack#197 --- docker-entrypoint.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 01fd8446..03ddcfc9 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,10 +1,12 @@ #!/bin/bash set -e -DB_PORT=${DB_PORT:-3306} - echoerr() { echo "$@" 1>&2; } +# Split out host and port from DB_HOST env variable +IFS=":" read -r DB_HOST_NAME DB_PORT <<< "$DB_HOST" +DB_PORT=${DB_PORT:-3306} + if [ ! -f '/var/www/BookStack/.env' ]; then if [[ "${DB_HOST}" ]]; then cat > /var/www/BookStack/.env <&2 'error: missing DB_PORT or DB_HOST environment variables' + echo >&2 'error: missing DB_HOST environment variable' exit 1 fi fi -echoerr wait-for-db: waiting for ${DB_HOST}:${DB_PORT} +echoerr wait-for-db: waiting for ${DB_HOST_NAME}:${DB_PORT} timeout 15 bash < /dev/tcp/${DB_HOST}/${DB_PORT}) >/dev/null 2>&1; +while ! (echo > /dev/tcp/${DB_HOST_NAME}/${DB_PORT}) >/dev/null 2>&1; do sleep 1; done; EOT @@ -98,7 +99,7 @@ if [ $RESULT -eq 0 ]; then sleep 1 echoerr wait-for-db: done else - echoerr wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST}:${DB_PORT} + echoerr wait-for-db: timeout out after 15 seconds waiting for ${DB_HOST_NAME}:${DB_PORT} fi cd /var/www/BookStack/ && php artisan key:generate && php artisan migrate --force