#!/bin/bash # ========================================================================= # CONFIGURATION & ENVIRONMENT # ========================================================================= export HOME=/root export COMPOSER_HOME=/root/.composer export PATH=$PATH:/usr/local/bin:/usr/bin:/bin PROJECT_PATH="/www/wwwroot/academy.nihonbuzz.org" PHP_BIN="/www/server/php/83/bin/php" # --- CONFIG TELEGRAM --- # Load from .env if available if [ -f .env ]; then export $(grep -v '^#' .env | xargs) fi BOT_TOKEN="${TELEGRAM_BOT_TOKEN}" CHAT_ID="${TELEGRAM_CHAT_ID}" send_telegram() { local message="$1" curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \ -d chat_id="$CHAT_ID" \ -d text="$message" \ -d parse_mode="HTML" > /dev/null } # ========================================================================= # START DEPLOYMENT # ========================================================================= echo "๐Ÿš€ Starting Deployment..." send_telegram "โณ Deployment Started%0A%0A๐Ÿš€ Project: Nihonbuzz Academy%0A๐Ÿ“… Date: $(date)" set -e git config --global --add safe.directory "$PROJECT_PATH" cd "$PROJECT_PATH" trap 'send_telegram "โŒ Deployment FAILED!%0A%0Aโš ๏ธ Check server logs untuk detail.%0A๐Ÿ“… Date: $(date)"; exit 1' ERR # 3. Pull & Clean echo "๐Ÿ“ฅ Pulling latest code..." git pull origin main echo "๐Ÿงน Cleaning untracked files..." # CATATAN: Karena .well-known terhapus, pastikan Anda tidak sedang proses renewal SSL git clean -fd # 4. PHP Dependencies echo "๐Ÿ“ฆ Updating Composer dependencies..." $PHP_BIN /usr/bin/composer install --no-dev --optimize-autoloader --no-interaction # 5. Frontend Assets (URUTAN DIPERBAIKI) echo "๐Ÿ“ฆ Building frontend assets..." npm install echo "๐Ÿ”ง Fixing permissions..." find node_modules -type f \( -path "*/bin/*" -o -path "*/.bin/*" \) -exec chmod +x {} \; if [ -d "node_modules/@esbuild/linux-x64/bin" ]; then chmod +x node_modules/@esbuild/linux-x64/bin/esbuild fi rm -rf public/build echo "๐Ÿ— Running Vite build..." npx vite build # Prune SEKARANG setelah build sukses echo "๐Ÿงน Pruning dev dependencies..." npm prune --omit=dev # 6. Environment Setup # NOTE: Adjusted to use the new standardized naming if available, otherwise fallback if [ -f .env.production.editable ]; then echo "๐Ÿ“„ Updating .env from .env.production.editable..." cp .env.production.editable .env elif [ ! -f .env ]; then # Fallback legacy cp .env.production.example .env fi # 6.5 Ensure SQLite Database Exists DB_FILE="$PROJECT_PATH/database/database.sqlite" if [ ! -f "$DB_FILE" ]; then echo "๐Ÿ—„๏ธ Creating SQLite database file..." touch "$DB_FILE" fi # 7. Laravel Optimizations echo "โšก Optimizing Laravel..." # Clear config first to ensure migration uses latest .env $PHP_BIN artisan config:clear # Migrate database to ensure tables (like cache) exist $PHP_BIN artisan migrate --force # Now clear all caches (including DB-based cache) $PHP_BIN artisan optimize:clear # NEW: Conditional CA Data Migration (Optional, uncomment if needed routinely) # $PHP_BIN artisan ca:migrate-data $PHP_BIN artisan config:cache $PHP_BIN artisan route:cache $PHP_BIN artisan view:cache echo "โœ… Deployment SUCCESS!" send_telegram "โœ… Deployment Success!%0A%0A๐Ÿ“ฆ Project: Nihonbuzz Academy%0A๐Ÿ“… Date: $(date)"