forked from BLC/sgeUpdated
main #1
@@ -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
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main # trigger only when code is merged into main
|
||||
workflow_dispatch: # allow manual trigger
|
||||
- main # Trigger when code is pushed/merged into main
|
||||
workflow_dispatch: # Allow manual trigger
|
||||
|
||||
concurrency:
|
||||
group: sgeupdated-deploy-${{ github.ref }}
|
||||
@@ -14,11 +21,12 @@ concurrency:
|
||||
jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Deploy over SSH
|
||||
- name: Deploy Application (Backend & Frontend)
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
with:
|
||||
host: ${{ secrets.SERVER_HOST }}
|
||||
@@ -26,24 +34,47 @@ jobs:
|
||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
script_stop: true
|
||||
script: |
|
||||
# Exit immediately if any command fails
|
||||
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 reset --hard origin/main
|
||||
|
||||
echo "⚡ Rebuilding Backend..."
|
||||
cd sgeUpdated/sge-backend
|
||||
echo "⚙️ Rebuilding Backend..."
|
||||
# 3. Go to the backend folder (FIXED PATH)
|
||||
cd sge-backend
|
||||
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
|
||||
cd ../..
|
||||
docker compose up -d --build bgreen-backend
|
||||
cd .. # Back to sgeUpdated root
|
||||
|
||||
echo "⚡ Rebuilding Frontend..."
|
||||
cd sgeUpdated/sge-frontend
|
||||
# npm install
|
||||
echo "⚙️ Rebuilding Frontend..."
|
||||
# 4. Go to the frontend folder (FIXED PATH)
|
||||
cd sge-frontend
|
||||
# Uncomment these if you need to build your frontend
|
||||
# echo "Installing frontend dependencies..."
|
||||
# npm ci
|
||||
# echo "Building frontend..."
|
||||
# npm run build
|
||||
cd ../..
|
||||
docker compose up -d --build bgreen-frontend
|
||||
cd .. # Back to sgeUpdated root
|
||||
|
||||
echo "✅ Deployment complete. Current containers:"
|
||||
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
||||
# 5. Go back to the main project directory
|
||||
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