diff --git a/Dockerfile b/Dockerfile index 39266fe..f225dac 100755 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM php:7.3-fpm -RUN apt-get update && apt-get install -y openssh-server unzip git msmtp nginx \ +RUN apt-get update && apt-get install -y openssh-server unzip git msmtp nginx wait-for-it \ && rm /etc/nginx/sites-enabled/default \ && apt-get -y autoremove \ && apt-get clean \ diff --git a/init b/init index 2de3ee4..e5b558c 100755 --- a/init +++ b/init @@ -79,6 +79,17 @@ if [ "${role}" = "app" -a -e artisan ]; then if [ -r .migrate ]; then echo "* Running migration..." + # If DB_HOST not set, source the env file + [ -z "${DB_HOST}" -a -r .env ] && . .env + + if [ -n "${DB_HOST}" -a -n "${DB_PORT}" ]; then + while ! wait-for-it -h ${DB_HOST} -p ${DB_PORT} -t 5 -q; do + echo "? Waiting for database at ${DB_HOST}:${DB_PORT}" + sleep 1; + done + echo "- DB is active on ${DB_HOST}:${DB_PORT}" + fi + su www-data -s /bin/sh -c "php artisan migrate" && rm -f .migrate fi