Skip to content

Commit 706a55f

Browse files
committed
fixing rollout deployment & Build
1 parent 02142ee commit 706a55f

File tree

4 files changed

+87
-19
lines changed

4 files changed

+87
-19
lines changed

.github/workflows/rpgf5-staging-deploy.yml

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
uses: appleboy/[email protected]
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+
uses: appleboy/[email protected]
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"

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ COPY package*.json ./
55
COPY tsconfig*.json ./
66
RUN npm install -g @nestjs/cli
77
RUN npm install
8+
RUN apk add git curl
89
COPY . .
910
RUN npm run build
1011
EXPOSE 7070

docker-compose-prod.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42
pw-backend1:
53
image: ghcr.io/generalmagicio/rpgf5-be:main
@@ -11,6 +9,12 @@ services:
119
- .env
1210
networks:
1311
- pw-backend
12+
healthcheck:
13+
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
14+
interval: 30s
15+
timeout: 10s
16+
retries: 5
17+
start_period: 60s
1418

1519
pw-backend2:
1620
image: ghcr.io/generalmagicio/rpgf5-be:main
@@ -22,7 +26,13 @@ services:
2226
- .env
2327
networks:
2428
- pw-backend
25-
29+
healthcheck:
30+
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
31+
interval: 30s
32+
timeout: 10s
33+
retries: 5
34+
start_period: 60s
35+
2636
caddy:
2737
image: caddy:2-alpine
2838
container_name: caddy

docker-compose-staging.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3'
2-
31
services:
42
pw-backend1:
53
image: ghcr.io/generalmagicio/rpgf5-be:staging
@@ -11,6 +9,12 @@ services:
119
- .env
1210
networks:
1311
- pw-backend
12+
healthcheck:
13+
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
14+
interval: 30s
15+
timeout: 10s
16+
retries: 5
17+
start_period: 60s
1418

1519
pw-backend2:
1620
image: ghcr.io/generalmagicio/rpgf5-be:staging
@@ -22,6 +26,12 @@ services:
2226
- .env
2327
networks:
2428
- pw-backend
29+
healthcheck:
30+
test: ['CMD', 'curl', '-f', 'http://localhost:7070']
31+
interval: 30s
32+
timeout: 10s
33+
retries: 5
34+
start_period: 60s
2535

2636
caddy:
2737
image: caddy:2-alpine

0 commit comments

Comments
 (0)