forked from BLC/sgeUpdated
++
This commit is contained in:
@@ -1,11 +1,18 @@
|
|||||||
# .gitea/workflows/sgeupdated.yml
|
# This is the full workflow file with all fixes applied.
|
||||||
|
#
|
||||||
|
# It fixes:
|
||||||
|
# 1. Path errors (cd sge-backend)
|
||||||
|
# 2. Docker 'container removal' errors (by adding 'docker compose down')
|
||||||
|
# 3. Runs 'docker compose' from the correct directory (/home/ubuntu/Bgreen)
|
||||||
|
# 4. Combines backend and frontend into one efficient step
|
||||||
|
|
||||||
name: sgeUpdated CI/CD
|
name: sgeUpdated CI/CD
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # trigger only when code is merged into main
|
- main # Trigger when code is pushed/merged into main
|
||||||
workflow_dispatch: # allow manual trigger
|
workflow_dispatch: # Allow manual trigger
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: sgeupdated-deploy-${{ github.ref }}
|
group: sgeupdated-deploy-${{ github.ref }}
|
||||||
@@ -14,11 +21,12 @@ concurrency:
|
|||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Deploy over SSH
|
- name: Deploy Application (Backend & Frontend)
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SERVER_HOST }}
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
@@ -26,24 +34,47 @@ jobs:
|
|||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
script_stop: true
|
script_stop: true
|
||||||
script: |
|
script: |
|
||||||
|
# Exit immediately if any command fails
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
cd /home/ubuntu/Bgreen/sgeUpdated
|
echo "🚀 Starting deployment..."
|
||||||
|
|
||||||
|
# 1. Go to the main project directory (where docker-compose.yml is)
|
||||||
|
cd /home/ubuntu/Bgreen
|
||||||
|
|
||||||
|
echo "🔄 Pulling latest code..."
|
||||||
|
# 2. Go into the repo sub-directory to pull
|
||||||
|
cd sgeUpdated
|
||||||
git fetch origin main
|
git fetch origin main
|
||||||
git reset --hard origin/main
|
git reset --hard origin/main
|
||||||
|
|
||||||
echo "⚡ Rebuilding Backend..."
|
echo "⚙️ Rebuilding Backend..."
|
||||||
cd sgeUpdated/sge-backend
|
# 3. Go to the backend folder (FIXED PATH)
|
||||||
|
cd sge-backend
|
||||||
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
||||||
cd ../..
|
cd .. # Back to sgeUpdated root
|
||||||
docker compose up -d --build bgreen-backend
|
|
||||||
|
|
||||||
echo "⚡ Rebuilding Frontend..."
|
echo "⚙️ Rebuilding Frontend..."
|
||||||
cd sgeUpdated/sge-frontend
|
# 4. Go to the frontend folder (FIXED PATH)
|
||||||
# npm install
|
cd sge-frontend
|
||||||
|
# Uncomment these if you need to build your frontend
|
||||||
|
# echo "Installing frontend dependencies..."
|
||||||
|
# npm ci
|
||||||
|
# echo "Building frontend..."
|
||||||
# npm run build
|
# npm run build
|
||||||
cd ../..
|
cd .. # Back to sgeUpdated root
|
||||||
docker compose up -d --build bgreen-frontend
|
|
||||||
|
|
||||||
echo "✅ Deployment complete. Current containers:"
|
# 5. Go back to the main project directory
|
||||||
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
cd ..
|
||||||
|
# (We are now in /home/ubuntu/Bgreen)
|
||||||
|
|
||||||
|
echo "🛑 Stopping existing services... (FIX for Docker error)"
|
||||||
|
# 6. Stop services cleanly before building
|
||||||
|
docker compose down
|
||||||
|
|
||||||
|
echo "🚀 Launching new services..."
|
||||||
|
# 7. Build and start all services from the correct directory
|
||||||
|
docker compose up -d --build --remove-orphans
|
||||||
|
|
||||||
|
echo "✅ Deployment complete!"
|
||||||
|
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
||||||
|
|||||||
Reference in New Issue
Block a user