mirror of
https://github.com/nihonbuzz/nihonbuzz-academy.git
synced 2026-01-25 21:18:45 +07:00
109 lines
3.3 KiB
Bash
109 lines
3.3 KiB
Bash
#!/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 "⏳ <b>Deployment Started</b>%0A%0A🚀 <b>Project:</b> Nihonbuzz Academy%0A📅 <b>Date:</b> $(date)"
|
||
|
||
set -e
|
||
|
||
git config --global --add safe.directory "$PROJECT_PATH"
|
||
cd "$PROJECT_PATH"
|
||
|
||
trap 'send_telegram "❌ <b>Deployment FAILED!</b>%0A%0A⚠️ Check server logs untuk detail.%0A📅 <b>Date:</b> $(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 "✅ <b>Deployment Success!</b>%0A%0A📦 <b>Project:</b> Nihonbuzz Academy%0A📅 <b>Date:</b> $(date)"
|