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