@@ -42,25 +42,72 @@ jobs:
4242 port : ${{ secrets.SSH_PORT }}
4343 script : |
4444 cd pw-backend
45- git reset --hard HEAD~1
45+ git reset --hard origin/master
4646 git checkout master
4747 git pull origin master
4848 docker image prune -a --force
4949 docker compose -f docker-compose-prod.yml pull
5050
51+ rollout-deploy-1 :
52+ needs : deploy
53+ runs-on : ubuntu-latest
54+ steps :
55+ - name : SSH and Redeploy
56+ 57+ with :
58+ host : ${{ secrets.RPGF5_PROD_HOST }}
59+ username : ${{ secrets.RPGF5_PROD_USERNAME }}
60+ key : ${{ secrets.RPGF5_PROD_PRIVATE_KEY }}
61+ port : ${{ secrets.SSH_PORT }}
62+ script : |
63+ cd pw-backend
5164 ## Update each backend service one by one
52- docker compose -f docker-compose-prod.yml up -d --no-deps --scale pw-backend1=0 --scale pw-backend2=1
53- docker compose -f docker-compose-prod.yml up -d
54- # Check the health of pw-backend1
55- if [ "$(docker inspect --format='{{json .State.Status}}' pw-backend1)" != "\"running\"" ]; then
56- echo "pw-backend1 is not running, stopping deployment"
57- exit 1
65+ ## First Deployment
66+ docker compose -f docker-compose-prod.yml rm -fs pw-backend1
67+ docker compose -f docker-compose-prod.yml up --force-recreate -d pw-backend1
68+
69+ # Wait for pw-backend1 to be healthy (timeout after 5 minutes)
70+ echo "Waiting for pw-backend1 to become healthy..."
71+ timeout 300 bash -c 'until [ "$(docker inspect --format="{{json .State.Health.Status}}" pw-backend1)" == "\"healthy\"" ]; do echo "Waiting for pw-backend1 to be healthy..."; sleep 5; done'
72+ if [ $? -eq 124 ]; then
73+ echo "Timeout waiting for pw-backend1 to become healthy"
74+ exit 1
75+ fi
76+ # Check if pw-backend1 is healthy
77+ if [ "$(docker inspect --format='{{json .State.Health.Status}}' pw-backend1)" != "\"healthy\"" ]; then
78+ echo "pw-backend1 is not healthy, stopping deployment"
79+ exit 1
5880 fi
81+ echo "First deployment phase completed successfully"
82+
83+ rollout-deploy-2 :
84+ needs : rollout-deploy-1
85+ runs-on : ubuntu-latest
86+ steps :
87+ - name : SSH and Redeploy
88+ 89+ with :
90+ host : ${{ secrets.RPGF5_PROD_HOST }}
91+ username : ${{ secrets.RPGF5_PROD_USERNAME }}
92+ key : ${{ secrets.RPGF5_PROD_PRIVATE_KEY }}
93+ port : ${{ secrets.SSH_PORT }}
94+ script : |
95+ cd pw-backend
96+ ## Update each backend service one by one
97+ ## Second Deployment
98+ docker compose -f docker-compose-prod.yml rm -fs pw-backend2
99+ docker compose -f docker-compose-prod.yml up --force-recreate -d pw-backend2
59100
60- docker compose -f docker-compose-prod.yml up -d --no-deps --scale pw-backend1=1 --scale pw-backend2=0
61- docker compose -f docker-compose-prod.yml up -d
62- # Check the health of pw-backend2
63- if [ "$(docker inspect --format='{{json .State.Status}}' pw-backend2)" != "\"running\"" ]; then
64- echo "pw-backend2 is not running, stopping deployment"
65- exit 1
66- fi
101+ # Wait for pw-backend2 to be healthy (timeout after 5 minutes)
102+ echo "Waiting for pw-backend2 to become healthy..."
103+ timeout 300 bash -c 'until [ "$(docker inspect --format="{{json .State.Health.Status}}" pw-backend2)" == "\"healthy\"" ]; do echo "Waiting for pw-backend2 to be healthy..."; sleep 5; done'
104+ if [ $? -eq 124 ]; then
105+ echo "Timeout waiting for pw-backend2 to become healthy"
106+ exit 1
107+ fi
108+ # Check if pw-backend2 is healthy
109+ if [ "$(docker inspect --format='{{json .State.Health.Status}}' pw-backend2)" != "\"healthy\"" ]; then
110+ echo "pw-backend2 is not healthy, stopping deployment"
111+ exit 1
112+ fi
113+ echo "Second deployment phase completed successfully"
0 commit comments