forked from Abdulbari/sgeUpdated
Update sgeupdated pipeline v17
a clone of the aypos yml file to test it
This commit is contained in:
@@ -1,57 +1,97 @@
|
|||||||
# .gitea/workflows/sgeupdated.yml
|
name: SgeUpdated Deploy
|
||||||
name: sgeUpdated CI/CD
|
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ "main" ]
|
||||||
- main # trigger only when code is merged into main
|
workflow_dispatch:
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: sgeupdated-deploy-${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy-frontend:
|
||||||
runs-on: ubuntu-latest
|
if: contains(github.event.head_commit.message, '[frontend]') || github.event_name == 'workflow_dispatch'
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Deploy Frontend over SSH
|
||||||
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
|
||||||
|
|
||||||
script: |
|
echo "==== Frontend Deploy ===="
|
||||||
cd /home/ubuntu/sgeUpdated
|
cd "$FRONTEND_DIR"
|
||||||
git fetch origin main
|
git fetch origin main
|
||||||
git reset --hard origin/main
|
git checkout -B main origin/main
|
||||||
|
echo "Frontend repo now: $(git rev-parse --short HEAD)"
|
||||||
|
|
||||||
echo "🔍 Detecting changes..."
|
cd "$PROJECT_DIR"
|
||||||
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD || true)
|
echo ":: Rebuild & restart $SERVICE"
|
||||||
echo "Changed files: $CHANGED_FILES"
|
docker compose up -d --build "$SERVICE"
|
||||||
|
|
||||||
# --- Backend ---
|
echo ":: Health check (retry up to 60s)"
|
||||||
if echo "$CHANGED_FILES" | grep -E "(^|/)sge-backend/"; then
|
for i in $(seq 1 20); do
|
||||||
echo "⚙️ Backend changes detected. Rebuilding backend..."
|
if curl -fsSI --max-time 3 "$SMOKE_URL" >/dev/null; then
|
||||||
cd sge-backend
|
echo "Frontend healthy ✅"
|
||||||
mvn clean install -DskipTests
|
break
|
||||||
cd ..
|
fi
|
||||||
docker compose build --no-cache backend
|
echo "Waiting..."
|
||||||
docker compose up -d --force-recreate backend
|
docker compose logs --tail=50 "$SERVICE" || true
|
||||||
else
|
sleep 3
|
||||||
echo "✅ No backend changes detected."
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
# --- Frontend ---
|
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
||||||
if echo "$CHANGED_FILES" | grep -E "(^|/)sge-frontend/"; then
|
|
||||||
echo "⚙️ Frontend changes detected. Rebuilding frontend..."
|
|
||||||
cd sge-frontend
|
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
cd ..
|
|
||||||
docker compose build --no-cache frontend
|
|
||||||
docker compose up -d --force-recreate frontend
|
|
||||||
else
|
|
||||||
echo "✅ No frontend changes detected."
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
deploy-backend:
|
||||||
|
if: contains(github.event.head_commit.message, '[backend]') || github.event_name == 'workflow_dispatch'
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- name: Deploy Backend over SSH
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
env:
|
||||||
|
PROJECT_DIR: /home/ubuntu/sgeUpdated
|
||||||
|
BACKEND_DIR: /home/ubuntu/sgeUpdated/sge-backend
|
||||||
|
SERVICE: sgeupdated-backend
|
||||||
|
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}}'
|
||||||
|
|||||||
Reference in New Issue
Block a user