feat: add entrypoint script to handle environment configuration, database readiness, and service startup
This commit is contained in:
@@ -14,10 +14,26 @@ fi
|
||||
|
||||
php artisan config:clear --no-ansi
|
||||
|
||||
if ! grep -q '^APP_KEY=base64:' .env 2>/dev/null; then
|
||||
# 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user