@@ -27,32 +27,23 @@ jobs:
2727
2828 - name : SSH to VM and deploy
2929 run : |
30- ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_IP }} << 'REMOTE'
31- set -euo pipefail
32- echo "Entering project directory..."
33- cd '${{ secrets.PROJECT_PATH }}/frontend'
34- echo "Pulling latest from origin/main..."
35- git fetch origin main
36- git reset --hard origin/main
37- echo "Stopping frontend service (if running)..."
38- docker compose -f compose.yml stop frontend || true
39- echo "Removing old container (if exists)..."
40- docker compose -f compose.yml rm -f frontend || true
41- echo "Building the frontend container..."
42- docker compose -f compose.yml build frontend
43- echo "Starting the frontend container in headless/detached mode..."
44- docker compose -f compose.yml up -d --no-deps --force-recreate frontend
45- echo "Cleaning up unused images and containers..."
46- docker image prune -af || true
47- docker container prune -f || true
48- docker system prune -f || true
49- echo "Deployment finished successfully."
50- exit 0
51- REMOTE
52- ssh_exit=$?
53- echo "SSH client exit code: $ssh_exit"
54- if [ "$ssh_exit" -ne 0 ]; then
55- echo "ERROR: SSH command returned non-zero exit code: $ssh_exit"
56- exit $ssh_exit
57- fi
58- echo "Workflow step completed (ssh returned 0)."
30+ ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_IP }} "
31+ echo "Entering project directory..."
32+ cd ${{ secrets.PROJECT_PATH }}/frontend
33+ echo "Pulling latest from origin/main..."
34+ git fetch origin main
35+ git reset --hard origin/main
36+ echo "Stopping frontend service (if running)..."
37+ docker compose stop frontend
38+ echo "Removing old container (if exists)..."
39+ docker compose rm -f frontend
40+ echo "Building the frontend container..."
41+ docker compose build frontend
42+ echo "Starting the frontend container in headless mode..."
43+ docker compose up -d --no-deps --force-recreate frontend
44+ echo "Cleaning up unused images and containers..."
45+ docker image prune -af
46+ docker container prune -f
47+ docker system prune -f
48+ echo "Deployment finished successfully.
49+ "
0 commit comments