diff --git a/.gitea/workflows/sgeupdated.yml b/.gitea/workflows/sgeupdated.yml index ed40a11..f3e7bf9 100644 --- a/.gitea/workflows/sgeupdated.yml +++ b/.gitea/workflows/sgeupdated.yml @@ -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}}' \ No newline at end of file + # 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}}' diff --git a/sge-backend/pom.xml b/sge-backend/pom.xml index 253aacd..772e2fa 100644 --- a/sge-backend/pom.xml +++ b/sge-backend/pom.xml @@ -11,7 +11,7 @@ com.sgs sgs - 0.0.5-SNAPSHOT + 0.0.4-SNAPSHOT sgs SGS project for Spring Boot