This commit is contained in:
2025-12-17 18:17:53 +03:00
parent a7ba6fe3e4
commit 7a948f3b7e

View File

@@ -3,6 +3,18 @@ set -euo pipefail
cd /home/ubuntu/Bgreen/sgeUpdated cd /home/ubuntu/Bgreen/sgeUpdated
# -----------------------
# Harbor settings
# -----------------------
HARBOR_REGISTRY="10.150.1.166"
HARBOR_PROJECT="bgreen"
BACKEND_IMAGE_REPO="${HARBOR_REGISTRY}/${HARBOR_PROJECT}/bgreen-backend"
FRONTEND_IMAGE_REPO="${HARBOR_REGISTRY}/${HARBOR_PROJECT}/bgreen-frontend"
# Tag images with git commit (better than latest; enables rollback)
VERSION="$(git rev-parse --short HEAD)"
echo "📦 Fetching latest changes from origin/main..." echo "📦 Fetching latest changes from origin/main..."
git fetch myfork main git fetch myfork main
@@ -22,12 +34,12 @@ git reset --hard myfork/main
BACKEND_CHANGED=false BACKEND_CHANGED=false
FRONTEND_CHANGED=false FRONTEND_CHANGED=false
# Check if backend folder changed # Check if backend folder changed (excluding README.md)
if echo "$CHANGED_FILES" | grep "^sge-backend/" | grep -qv "README.md$"; then if echo "$CHANGED_FILES" | grep "^sge-backend/" | grep -qv "README.md$"; then
BACKEND_CHANGED=true BACKEND_CHANGED=true
fi fi
# Check if frontend folder changed # Check if frontend folder changed (excluding README.md)
if echo "$CHANGED_FILES" | grep "^sge-frontend/" | grep -qv "README.md$"; then if echo "$CHANGED_FILES" | grep "^sge-frontend/" | grep -qv "README.md$"; then
FRONTEND_CHANGED=true FRONTEND_CHANGED=true
fi fi
@@ -37,12 +49,25 @@ fi
# ----------------------- # -----------------------
if [ "$BACKEND_CHANGED" = true ]; then if [ "$BACKEND_CHANGED" = true ]; then
echo "⚡ Backend changes detected." echo "⚡ Backend changes detected."
cd sge-backend cd sge-backend
echo "Running Maven build..." echo "Running Maven build..."
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests /opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
cd ../..
echo "Rebuilding backend Docker container..." echo "🐳 Building backend Docker image..."
docker compose up -d --build bgreen-backend docker build -t "${BACKEND_IMAGE_REPO}:${VERSION}" .
echo "📤 Pushing backend image to Harbor..."
docker push "${BACKEND_IMAGE_REPO}:${VERSION}"
echo "📥 Pulling backend image from Harbor (to ensure registry is source of truth)..."
docker pull "${BACKEND_IMAGE_REPO}:${VERSION}"
cd ..
echo "🚀 Recreating backend container using Harbor image..."
VERSION="$VERSION" docker compose up -d bgreen-backend
else else
echo "✅ No backend changes." echo "✅ No backend changes."
fi fi
@@ -56,7 +81,7 @@ if [ "$FRONTEND_CHANGED" = true ]; then
# Check if package.json or package-lock.json changed # Check if package.json or package-lock.json changed
if echo "$CHANGED_FILES" | grep -qE "^sge-frontend/(package\.json|package-lock\.json)$"; then if echo "$CHANGED_FILES" | grep -qE "^sge-frontend/(package\.json|package-lock\.json)$"; then
echo "📦 package.json changed. Running 'npm instal' and 'npm run build'..." echo "📦 package.json changed. Running 'npm install' and 'npm run build'..."
npm install npm install
npm run build npm run build
else else
@@ -64,9 +89,20 @@ if [ "$FRONTEND_CHANGED" = true ]; then
npm run build npm run build
fi fi
cd ../.. echo "🐳 Building frontend Docker image..."
echo "Rebuilding frontend Docker container..." docker build -t "${FRONTEND_IMAGE_REPO}:${VERSION}" .
docker compose up -d --build bgreen-frontend
echo "📤 Pushing frontend image to Harbor..."
docker push "${FRONTEND_IMAGE_REPO}:${VERSION}"
echo "📥 Pulling frontend image from Harbor (to ensure registry is source of truth)..."
docker pull "${FRONTEND_IMAGE_REPO}:${VERSION}"
cd ..
echo "🚀 Recreating frontend container using Harbor image..."
VERSION="$VERSION" docker compose up -d bgreen-frontend
else else
echo "✅ No frontend changes." echo "✅ No frontend changes."
fi fi