43 lines
1.2 KiB
Bash
43 lines
1.2 KiB
Bash
#!/usr/bin/env sh
|
|
set -e
|
|
|
|
cd /var/www/html
|
|
|
|
if [ ! -f .env ] && [ -f .env.docker.example ]; then
|
|
cp .env.docker.example .env
|
|
fi
|
|
|
|
if [ ! -f vendor/autoload.php ]; then
|
|
echo "vendor/autoload.php is missing. Rebuild the image so Composer dependencies are baked in."
|
|
exit 1
|
|
fi
|
|
|
|
php artisan config:clear --no-ansi
|
|
|
|
# Coolify menyuntik APP_KEY lewat environment variable, jadi key:generate
|
|
# hanya perlu jalan kalau key tidak ada di env maupun .env
|
|
if [ -z "${APP_KEY:-}" ] && ! grep -q '^APP_KEY=base64:' .env 2>/dev/null; then
|
|
php artisan key:generate --force --no-ansi
|
|
fi
|
|
|
|
DB_WAIT_HOST="${DB_HOST:-mysql}"
|
|
DB_WAIT_PORT="${DB_PORT:-3306}"
|
|
echo "Waiting for database at ${DB_WAIT_HOST}:${DB_WAIT_PORT}..."
|
|
tries=0
|
|
until mysqladmin ping -h "$DB_WAIT_HOST" -P "$DB_WAIT_PORT" --silent 2>/dev/null; do
|
|
tries=$((tries + 1))
|
|
if [ "$tries" -ge 30 ]; then
|
|
echo "Database at ${DB_WAIT_HOST}:${DB_WAIT_PORT} is unreachable after ${tries} attempts."
|
|
echo "Check that DB_HOST points to a reachable MySQL host on the same Docker network."
|
|
exit 1
|
|
fi
|
|
sleep 2
|
|
done
|
|
|
|
php artisan migrate --force --no-ansi
|
|
php artisan db:seed --force --no-ansi
|
|
|
|
php artisan schedule:work --no-interaction > /dev/null 2>&1 &
|
|
|
|
exec "$@"
|