dummybot/docker-entrypoint.sh

24 lines
882 B
Bash

#!/bin/bash
# Change ownership and permissions
chown -R www-data:www-data /var/www
chmod -R 755 /var/www/storage
chmod -R 755 /var/www/bootstrap/cache
# Run migrations on first boot if AUTO_MIGRATE=1.
# We wait for the DB to be reachable (max 60 s) to avoid race with the db container.
if [ "${AUTO_MIGRATE:-0}" = "1" ]; then
echo "[entrypoint] AUTO_MIGRATE=1 -> waiting for DB..."
for i in $(seq 1 60); do
if php -r "try { new PDO('mysql:host='.getenv('DB_HOST').';port='.getenv('DB_PORT').';dbname='.getenv('DB_DATABASE'), getenv('DB_USERNAME'), getenv('DB_PASSWORD')); exit(0); } catch (Exception \$e) { exit(1); }" 2>/dev/null; then
echo "[entrypoint] DB ready after ${i}s -> running migrations"
php artisan migrate --force --no-interaction
break
fi
sleep 1
done
fi
# Execute the main command
exec "$@"