-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (105 loc) · 4.26 KB
/
rpgf5-staging-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: rpgf5-staging-deploy-pipeline
on:
push:
branches:
- staging
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/generalmagicio/rpgf5-be:staging
deploy:
runs-on: ubuntu-latest
needs: publish
steps:
- name: SSH and Redeploy Production
uses: appleboy/[email protected]
with:
host: ${{ secrets.RPGF5_STAGING_HOST }}
username: ${{ secrets.RPGF5_STAGING_USERNAME }}
key: ${{ secrets.RPGF5_STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
git reset --hard origin/staging
git checkout staging
git pull origin staging
docker image prune -a --force
docker compose -f docker-compose-staging.yml pull
rollout-deploy-1:
needs: deploy
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.RPGF5_STAGING_HOST }}
username: ${{ secrets.RPGF5_STAGING_USERNAME }}
key: ${{ secrets.RPGF5_STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
## Update each backend service one by one
## First Deployment
docker compose -f docker-compose-staging.yml rm -fs pw-backend1
docker compose -f docker-compose-staging.yml up --force-recreate -d pw-backend1
# Wait for pw-backend1 to be healthy (timeout after 5 minutes)
echo "Waiting for pw-backend1 to become healthy..."
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'
if [ $? -eq 124 ]; then
echo "Timeout waiting for pw-backend1 to become healthy"
exit 1
fi
# Check if pw-backend1 is healthy
if [ "$(docker inspect --format='{{json .State.Health.Status}}' pw-backend1)" != "\"healthy\"" ]; then
echo "pw-backend1 is not healthy, stopping deployment"
exit 1
fi
echo "First deployment phase completed successfully"
rollout-deploy-2:
needs: rollout-deploy-1
runs-on: ubuntu-latest
steps:
- name: SSH and Redeploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.RPGF5_STAGING_HOST }}
username: ${{ secrets.RPGF5_STAGING_USERNAME }}
key: ${{ secrets.RPGF5_STAGING_PRIVATE_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd pw-backend
## Update each backend service one by one
## Second Deployment
docker compose -f docker-compose-staging.yml rm -fs pw-backend2
docker compose -f docker-compose-staging.yml up --force-recreate -d pw-backend2
# Wait for pw-backend2 to be healthy (timeout after 5 minutes)
echo "Waiting for pw-backend2 to become healthy..."
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'
if [ $? -eq 124 ]; then
echo "Timeout waiting for pw-backend2 to become healthy"
exit 1
fi
# Check if pw-backend2 is healthy
if [ "$(docker inspect --format='{{json .State.Health.Status}}' pw-backend2)" != "\"healthy\"" ]; then
echo "pw-backend2 is not healthy, stopping deployment"
exit 1
fi
echo "Second deployment phase completed successfully"