This repository has been archived on 2025-06-09. You can view files and clone it, but cannot push or open issues or pull requests.

79 lines
2.1 KiB
Bash
Raw Normal View History

2025-05-29 11:23:06 +08:00
#!/bin/bash
cd /var/www
# Remove trailing slash from APP_DOMAIN if exists
APP_DOMAIN="${APP_DOMAIN%/}"
# Default Redis settings
2025-05-29 11:23:06 +08:00
: "${REDIS_HOST:=redis}"
: "${REDIS_PORT:=6379}"
# Clone the project (only the first time)
2025-05-29 11:23:06 +08:00
if [ ! -d "html" ]; then
2025-05-29 12:54:50 +08:00
if [ -n "$GIT_REPO_URL" ]; then
echo "🔧 Cloning project from ${GIT_REPO_URL}..."
git clone "$GIT_REPO_URL" html
else
echo "❌ GIT_REPO_URL not set. Skipping clone."
exit 1
fi
2025-05-29 11:23:06 +08:00
fi
cd html
# Composer install
echo "📦 Running composer install..."
composer install --no-interaction --prefer-dist
# Copy .env file if not exists
2025-05-29 11:23:06 +08:00
if [ ! -f ".env" ]; then
echo "⚙️ Copying .env.example to .env"
cp .env.example .env
fi
# Update .env configurations
2025-05-29 11:23:06 +08:00
echo "🛠 Updating .env configurations..."
update_env_var() {
local key=$1
local value=$2
grep -q "^${key}=" .env && \
sed -i "s|^${key}=.*|${key}=${value}|" .env || \
echo "${key}=${value}" >> .env
}
update_env_var "APP_URL" "$APP_DOMAIN"
update_env_var "L5_SWAGGER_CONST_HOST" "$APP_DOMAIN"
update_env_var "DB_DATABASE" "$DB_DATABASE"
update_env_var "DB_USERNAME" "$DB_USERNAME"
update_env_var "DB_PASSWORD" "$DB_PASSWORD"
update_env_var "REDIS_HOST" "$REDIS_HOST"
update_env_var "REDIS_PORT" "$REDIS_PORT"
update_env_var "QUEUE_CONNECTION" "$QUEUE_CONNECTION"
update_env_var "CACHE_DRIVER" "$CACHE_DRIVER"
update_env_var "SESSION_DRIVER" "$SESSION_DRIVER"
# Laravel initialization
2025-05-29 11:23:06 +08:00
echo "🔑 Generating Laravel app key..."
php artisan key:generate
echo "🧱 Running migrations..."
php artisan config:clear && cache:clear
php artisan migrate --force
# Install Node.js packages and build frontend
2025-05-29 11:23:06 +08:00
echo "🌐 Installing npm packages..."
[ ! -d "node_modules" ] && npm install
echo "🛠 Building front-end assets..."
npm run build
# Add Laravel schedule to crontab (avoid duplicate entries)
2025-05-29 11:23:06 +08:00
echo "⏱ Adding schedule:run to crontab..."
crontab -l 2>/dev/null | grep -q 'schedule:run' || \
(echo "* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1" | crontab -)
# Start supervisord (to run queue + cron + php-fpm simultaneously)
2025-05-29 11:23:06 +08:00
echo "🚀 Starting supervisord..."
exec supervisord -n