bowler/docker/app/entrypoint.sh

40 lines
1.1 KiB
Bash

#!/bin/sh
set -e
cd /var/www/html
# Install PHP dependencies on first boot (the app is bind-mounted from ./src)
if [ ! -f vendor/autoload.php ]; then
echo "vendor/ missing - running composer install..."
composer install --no-interaction --prefer-dist --no-progress
fi
# Wait for the database to accept connections
echo "Waiting for database at ${DB_HOST}:${DB_PORT}..."
until php -r '
try {
new PDO(
"mysql:host=" . getenv("DB_HOST") . ";port=" . getenv("DB_PORT"),
getenv("DB_USERNAME"),
getenv("DB_PASSWORD"),
[PDO::ATTR_TIMEOUT => 3]
);
} catch (Throwable $e) {
exit(1);
}
' 2>/dev/null; do
echo " ...database not ready, retrying"
sleep 2
done
echo "Database is up."
php artisan migrate --force
php artisan db:seed --force
# Make runtime directories writable by the web server.
# chown can be a no-op or fail on Windows bind mounts - never fatal.
chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || true
chmod -R ugo+rwX storage bootstrap/cache 2>/dev/null || true
exec "$@"