Added wait-for-it to wait for DB for laravel

This commit is contained in:
Deon George 2020-05-07 21:29:21 +10:00
parent 90ed5a1da6
commit 81b970b53b
2 changed files with 12 additions and 1 deletions

View File

@ -3,7 +3,7 @@
FROM php:7.3-fpm 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 \ && rm /etc/nginx/sites-enabled/default \
&& apt-get -y autoremove \ && apt-get -y autoremove \
&& apt-get clean \ && apt-get clean \

11
init
View File

@ -79,6 +79,17 @@ if [ "${role}" = "app" -a -e artisan ]; then
if [ -r .migrate ]; then if [ -r .migrate ]; then
echo "* Running migration..." 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 su www-data -s /bin/sh -c "php artisan migrate" && rm -f .migrate
fi fi