feat(startup): add wait db live

pull/83/head
行旅途 2021-05-19 13:30:12 +08:00 committed by xxxxxliil
parent a47a8ab49e
commit 480775c328
2 changed files with 18 additions and 0 deletions

View File

@ -54,6 +54,7 @@ RUN apk add --no-progress --no-cache \
&& cd /tmp \
&& ln -s /usr/bin/php8 /usr/bin/php \
&& curl -s http://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& curl -L --progress-bar https://github.com/xxxxxliil/db-live-test/releases/download/0.0.1/db-live-test.php -o /usr/local/bin/db-live-test \
&& sed -i 's/memory_limit = .*/memory_limit = ${PHP_MEMORY_LIMIT}/' /etc/php8/php.ini \
&& chmod +x /usr/local/bin/composer \
&& mkdir -p /run/php /flarum/app \

View File

@ -65,6 +65,23 @@ if [ -f '/flarum/app/extensions/composer.repositories.txt' ]; then
done < /flarum/app/extensions/composer.repositories.txt
fi
# Wait database live
test_count=0
test_db(){
db-live-test --dsn "mysql:host=${DB_HOST};port=${DB_PORT};database=${DB_NAME}" \
--user ${DB_USER} \
--password ${DB_PASS}
}
echo "[INFO] Waiting for the database live..."
until test_db; do
if [ "${test_count}" = 40 ]; then
echo "[ERROR] The database not live!" >&2
exit 75
fi
test_count=$(($test_count + 1))
sleep 1
done
# if installation was performed before
if [ -e '/flarum/app/public/assets/rev-manifest.json' ] || [ -e '/flarum/app/public/assets/._flarum-installed.lock' ] ; then
echo "[INFO] Flarum already installed, init app..."