build and create deploy production

This commit is contained in:
arifal
2025-06-13 19:53:23 +07:00
parent 9437eb949f
commit 6677c320fc
28 changed files with 614 additions and 2570 deletions

View File

@@ -1,39 +1,52 @@
GIT_BRANCH="dev"
PHP_VERSION="php8.3"
#!/bin/bash
echo "🚀 Starting deployment..."
php artisan down
# Deploy script untuk build di local dan upload ke server
# Usage: ./deploy.sh [server-user] [server-host] [server-path]
echo "📥 Pulling latest changes from Git..."
git fetch origin $GIT_BRANCH
git reset --hard origin/$GIT_BRANCH
git pull origin $GIT_BRANCH
# Default values (ganti sesuai server Anda)
SERVER_USER=${1:-"your-username"}
SERVER_HOST=${2:-"your-server.com"}
SERVER_PATH=${3:-"/path/to/your/project"}
echo "⚡ Installing NPM dependencies and building assets..."
npm ci --no-audit --no-fund
echo "🚀 Starting deployment process..."
# 1. Clean previous build
echo "🧹 Cleaning previous build..."
rm -rf public/build/*
# 2. Install dependencies (jika belum)
echo "📦 Installing dependencies..."
npm ci --production=false
# 3. Build project
echo "🔨 Building project..."
npm run build
echo "📦 Installing composer dependencies..."
COMPOSER_ALLOW_SUPERUSER=1 composer install --no-interaction --optimize-autoloader
# Check if build was successful
if [ $? -ne 0 ]; then
echo "❌ Build failed!"
exit 1
fi
echo "🗄️ Running migrations..."
php artisan migrate --force
echo "✅ Build completed successfully!"
echo "Running seeders..."
php artisan db:seed --force
# 4. Upload build files to server
echo "📤 Uploading build files to server..."
rsync -avz --progress --delete public/build/ $SERVER_USER@$SERVER_HOST:$SERVER_PATH/public/build/
echo "⚡ Optimizing application..."
php artisan optimize:clear
# 5. Upload other necessary files (optional)
echo "📤 Uploading other files..."
rsync -avz --progress \
--exclude='node_modules' \
--exclude='.git' \
--exclude='public/build' \
--exclude='storage/logs/*' \
--exclude='bootstrap/cache/*' \
./ $SERVER_USER@$SERVER_HOST:$SERVER_PATH/
echo "🔄 Restarting PHP service..."
systemctl reload $PHP_VERSION-fpm
echo "🔁 Restarting Supervisor queue workers..."
php artisan queue:restart
supervisorctl reread
supervisorctl update
supervisorctl restart all
php artisan up
echo "🚀 Deployment completed successfully!"
echo "🎉 Deployment completed successfully!"
echo "Don't forget to run the following commands on the server:"
echo " - composer install --no-dev --optimize-autoloader"
echo " - php artisan config:cache"
echo " - php artisan route:cache"
echo " - php artisan view:cache"