forked from Abdulbari/sgeUpdated
70 lines
1.6 KiB
Bash
Executable File
70 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
export GIT_SSH_COMMAND="ssh -i ~/.ssh/deploy_id_rsa -o StrictHostKeyC
|
|
|
|
cd /home/ubuntu/Bgreen/sgeUpdated
|
|
|
|
echo "📦 Fetching latest changes from origin/main..."
|
|
git fetch origin main
|
|
|
|
# Detect which files changed between local HEAD and the latest remote version
|
|
CHANGED_FILES=$(git diff --name-only HEAD origin/main || true)
|
|
|
|
if [ -z "$CHANGED_FILES" ]; then
|
|
echo "✅ No file changes detected between HEAD and origin/main."
|
|
else
|
|
echo "🪶 Changed files:"
|
|
echo "$CHANGED_FILES"
|
|
fi
|
|
|
|
# Update to the latest version
|
|
git reset --hard origin/main
|
|
|
|
BACKEND_CHANGED=false
|
|
FRONTEND_CHANGED=false
|
|
|
|
# Check if backend folder changed
|
|
if echo "$CHANGED_FILES" | grep -q "^sge-backend/"; then
|
|
BACKEND_CHANGED=true
|
|
fi
|
|
|
|
# Check if frontend folder changed
|
|
if echo "$CHANGED_FILES" | grep -q "^sge-frontend/"; then
|
|
FRONTEND_CHANGED=true
|
|
fi
|
|
|
|
# -----------------------
|
|
# Backend section
|
|
# -----------------------
|
|
if [ "$BACKEND_CHANGED" = true ]; then
|
|
echo "⚡ Backend changes detected."
|
|
cd sge-backend
|
|
echo "Running Maven build..."
|
|
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
|
cd ..
|
|
echo "Rebuilding backend Docker container..."
|
|
docker compose up -d --build bgreen-backend
|
|
else
|
|
echo "✅ No backend changes."
|
|
fi
|
|
|
|
# -----------------------
|
|
# Frontend section
|
|
# -----------------------
|
|
if [ "$FRONTEND_CHANGED" = true ]; then
|
|
echo "⚡ Frontend changes detected."
|
|
cd sge-frontend
|
|
echo "Running npm build..."
|
|
npm install
|
|
npm run build
|
|
cd ..
|
|
echo "Rebuilding frontend Docker container..."
|
|
docker compose up -d --build bgreen-frontend
|
|
else
|
|
echo "✅ No frontend changes."
|
|
fi
|
|
|
|
echo "✅ Deployment complete."
|
|
|