Back to sgeupdated pipeline v16

This commit is contained in:
2025-09-01 02:46:07 +03:00
parent ae0e112572
commit 95afe7b877

View File

@@ -1,97 +1,56 @@
name: SgeUpdated Deploy # .gitea/workflows/sgeupdated.yml
name: sgeUpdated CI/CD
on: on:
push: push:
branches: [ "main" ] branches:
workflow_dispatch: - main # trigger only when code is merged into main
concurrency:
group: sgeupdated-deploy-${{ github.ref }}
cancel-in-progress: true
jobs: jobs:
deploy-frontend: deploy:
if: contains(github.event.head_commit.message, '[frontend]') || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps: steps:
- name: Deploy Frontend over SSH - name: Checkout repo
uses: actions/checkout@v3
- name: Deploy over SSH
uses: appleboy/ssh-action@v1.0.3 uses: appleboy/ssh-action@v1.0.3
env:
PROJECT_DIR: /home/ubuntu/sgeUpdated
FRONTEND_DIR: /home/ubuntu/sgeUpdated/sge-frontend
SERVICE: sgeupdated-frontend
SMOKE_URL: http://127.0.0.1:3000
with: with:
host: ${{ secrets.SERVER_HOST }} host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }} username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }} key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: PROJECT_DIR,FRONTEND_DIR,SERVICE,SMOKE_URL
script_stop: true script_stop: true
script: |
set -euo pipefail
echo "==== Frontend Deploy ====" script: |
cd "$FRONTEND_DIR" cd /home/ubuntu/sgeUpdated
git fetch origin main git fetch origin main
git checkout -B main origin/main git reset --hard origin/main
echo "Frontend repo now: $(git rev-parse --short HEAD)"
cd "$PROJECT_DIR" echo "🔍 Detecting changes..."
echo ":: Rebuild & restart $SERVICE" CHANGED_FILES=$(git diff --name-only HEAD^ HEAD || true)
docker compose up -d --build "$SERVICE" echo "Changed files: $CHANGED_FILES"
echo ":: Health check (retry up to 60s)" # --- Backend ---
for i in $(seq 1 20); do if echo "$CHANGED_FILES" | grep -E "(^|/)sge-backend/"; then
if curl -fsSI --max-time 3 "$SMOKE_URL" >/dev/null; then echo "⚙️ Backend changes detected. Rebuilding backend..."
echo "Frontend healthy ✅" cd sge-backend
break mvn clean install -DskipTests
fi cd ..
echo "Waiting..." docker compose build --no-cache backend
docker compose logs --tail=50 "$SERVICE" || true docker compose up -d --force-recreate backend
sleep 3 else
done echo "✅ No backend changes detected."
fi
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' # --- Frontend ---
if echo "$CHANGED_FILES" | grep -E "(^|/)sge-frontend/"; then
deploy-backend: echo "⚙️ Frontend changes detected. Rebuilding frontend..."
if: contains(github.event.head_commit.message, '[backend]') || github.event_name == 'workflow_dispatch' cd sge-frontend
runs-on: ubuntu-22.04 npm install
steps: npm run build
- name: Deploy Backend over SSH cd ..
uses: appleboy/ssh-action@v1.0.3 docker compose build --no-cache frontend
env: docker compose up -d --force-recreate frontend
PROJECT_DIR: /home/ubuntu/sgeUpdated else
BACKEND_DIR: /home/ubuntu/sgeUpdated/sge-backend echo "✅ No frontend changes detected."
SERVICE: sgeupdated-backend fi
SMOKE_URL: http://127.0.0.1:8080/actuator/health
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: PROJECT_DIR,BACKEND_DIR,SERVICE,SMOKE_URL
script_stop: true
script: |
set -euo pipefail
echo "==== Backend Deploy ===="
cd "$BACKEND_DIR"
git fetch origin main
git checkout -B main origin/main
echo "Backend repo now: $(git rev-parse --short HEAD)"
cd "$PROJECT_DIR"
echo ":: Rebuild & restart $SERVICE"
docker compose up -d --build "$SERVICE"
echo ":: Health check (retry up to 60s)"
for i in $(seq 1 20); do
if curl -fsSI --max-time 3 "$SMOKE_URL" >/dev/null; then
echo "Backend healthy ✅"
break
fi
echo "Waiting..."
docker compose logs --tail=50 "$SERVICE" || true
sleep 3
done
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'