Files
sgeUpdated/.gitea/workflows/sgeupdated.yml
2025-10-22 17:29:51 +03:00

81 lines
2.6 KiB
YAML

# 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 when code is pushed/merged into main
workflow_dispatch: # Allow manual trigger
concurrency:
group: sgeupdated-deploy-${{ github.ref }}
cancel-in-progress: true
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Deploy Application (Backend & Frontend)
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script_stop: true
script: |
# Exit immediately if any command fails
set -euo pipefail
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..."
# 3. Go to the backend folder (FIXED PATH)
cd sge-backend
/opt/apache-maven-3.9.11/bin/mvn clean install -DskipTests
cd .. # Back to sgeUpdated root
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 .. # Back to sgeUpdated root
# 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}}'