|
|
@ -0,0 +1,63 @@ |
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
set -eo pipefail |
|
|
|
|
|
|
|
|
|
|
|
PROJECT_DIR="/home/alialavi/projects/habib/marriage" |
|
|
|
|
|
cd "$PROJECT_DIR" |
|
|
|
|
|
|
|
|
|
|
|
LOG_TAG="[Marriage-Staging-Watcher]" |
|
|
|
|
|
|
|
|
|
|
|
# Ensure we are on staging branch |
|
|
|
|
|
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) |
|
|
|
|
|
if [ "$CURRENT_BRANCH" != "staging" ]; then |
|
|
|
|
|
echo "$LOG_TAG ⚠️ Currently on '$CURRENT_BRANCH', switching to 'staging'..." |
|
|
|
|
|
git checkout staging |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Fetch latest master and staging from origin |
|
|
|
|
|
git fetch origin master staging --quiet |
|
|
|
|
|
|
|
|
|
|
|
# Check 1: Commits ahead on origin/master |
|
|
|
|
|
MASTER_COMMITS=$(git rev-list --count HEAD..origin/master 2>/dev/null || echo 0) |
|
|
|
|
|
|
|
|
|
|
|
# Check 2: Commits ahead on origin/staging |
|
|
|
|
|
STAGING_COMMITS=$(git rev-list --count HEAD..origin/staging 2>/dev/null || echo 0) |
|
|
|
|
|
|
|
|
|
|
|
NEED_BUILD=0 |
|
|
|
|
|
|
|
|
|
|
|
if [ "$MASTER_COMMITS" -gt 0 ]; then |
|
|
|
|
|
echo "$LOG_TAG 🚀 Detected $MASTER_COMMITS new commit(s) on origin/master!" |
|
|
|
|
|
git log --oneline HEAD..origin/master |
|
|
|
|
|
echo "$LOG_TAG Merging origin/master into staging branch..." |
|
|
|
|
|
git merge origin/master --no-edit -m "chore(staging): auto-merge origin/master into staging" |
|
|
|
|
|
echo "$LOG_TAG Pushing updated staging branch to origin/staging..." |
|
|
|
|
|
git push origin staging --quiet |
|
|
|
|
|
NEED_BUILD=1 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ "$STAGING_COMMITS" -gt 0 ]; then |
|
|
|
|
|
echo "$LOG_TAG 🚀 Detected $STAGING_COMMITS new commit(s) on origin/staging!" |
|
|
|
|
|
git log --oneline HEAD..origin/staging |
|
|
|
|
|
echo "$LOG_TAG Pulling latest origin/staging..." |
|
|
|
|
|
git merge origin/staging --no-edit || git pull origin staging --no-edit |
|
|
|
|
|
NEED_BUILD=1 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
if [ "$NEED_BUILD" -eq 0 ]; then |
|
|
|
|
|
# Staging is completely up to date |
|
|
|
|
|
exit 0 |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# Rebuild and restart Next.js staging web container |
|
|
|
|
|
echo "$LOG_TAG Building and restarting marriage_staging_web container..." |
|
|
|
|
|
docker compose -f docker-compose.staging.yml up -d --build |
|
|
|
|
|
|
|
|
|
|
|
# Verify container health |
|
|
|
|
|
echo "$LOG_TAG Verifying service health..." |
|
|
|
|
|
sleep 5 |
|
|
|
|
|
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:5561/healthz || echo "000") |
|
|
|
|
|
|
|
|
|
|
|
if [ "$HTTP_STATUS" -eq 200 ]; then |
|
|
|
|
|
echo "$LOG_TAG ✅ SUCCESS: Marriage staging updated and healthy at commit $(git rev-parse --short HEAD) (HTTP 200 OK)." |
|
|
|
|
|
else |
|
|
|
|
|
echo "$LOG_TAG ⚠️ Health probe returned HTTP status $HTTP_STATUS" |
|
|
|
|
|
fi |