-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (123 loc) · 3.95 KB
/
Copy pathci-cd.yml
File metadata and controls
150 lines (123 loc) · 3.95 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Confero CI/CD
on:
push:
branches:
- main
- ahmd
- sameer
- dev
pull_request:
branches:
- main
jobs:
ci:
name: CI (Lint & Build)
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.2.2
- name: Setup Node.js
uses: actions/setup-node@v4.4.0
with:
node-version: 22
- name: Enable pnpm
run: |
corepack enable
corepack prepare pnpm@10.26.2 --activate
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint all packages
run: pnpm -r lint
- name: Build auth-service
run: pnpm --filter auth-service build
- name: Build live-service
run: pnpm --filter live-service build
- name: Prepare auth-service artifact
run: |
rm -rf auth-service-prod
mkdir auth-service-prod
cp -r services/auth-service/dist auth-service-prod/
cp services/auth-service/package.json auth-service-prod/
- name: Upload auth-service artifact
uses: actions/upload-artifact@v4.6.2
with:
name: auth-service-prod
path: auth-service-prod
- name: Prepare live-service artifact
run: |
rm -rf live-service-prod
mkdir live-service-prod
cp -r live-service/dist live-service-prod/
cp live-service/package.json live-service-prod/
- name: Upload live-service artifact
uses: actions/upload-artifact@v4.6.2
with:
name: live-service-prod
path: live-service-prod
- name: Build gateway
run: pnpm --filter gateway build
- name: Prepare gateway artifact
run: |
rm -rf gateway-prod
mkdir gateway-prod
cp -r gateway/dist gateway-prod/
cp gateway/package.json gateway-prod/
- name: Upload gateway artifact
uses: actions/upload-artifact@v4.6.2
with:
name: gateway-prod
path: gateway-prod
cd:
name: CD (Deploy to Azure VM)
needs: ci
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Download auth-service artifact
uses: actions/download-artifact@v4.3.0
with:
name: auth-service-prod
path: auth-service-prod
- name: Download live-service artifact
uses: actions/download-artifact@v4.3.0
with:
name: live-service-prod
path: live-service-prod
- name: Download gateway artifact
uses: actions/download-artifact@v4.3.0
with:
name: gateway-prod
path: gateway-prod
- name: Clean production directory
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.AZURE_HOST }}
username: ${{ secrets.AZURE_USER }}
key: ${{ secrets.AZURE_KEY }}
script: |
rm -rf /var/www/confero/auth-service-prod
rm -rf /var/www/confero/live-service-prod
rm -rf /var/www/confero/gateway-prod
# Upload artifacts
- name: Upload services to Azure
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.AZURE_HOST }}
username: ${{ secrets.AZURE_USER }}
key: ${{ secrets.AZURE_KEY }}
source: 'auth-service-prod,live-service-prod,gateway-prod'
target: /var/www/confero
# Restart services properly
- name: Reload backend services
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.AZURE_HOST }}
username: ${{ secrets.AZURE_USER }}
key: ${{ secrets.AZURE_KEY }}
script: |
cd /var/www/confero
npm install --omit=dev --prefix auth-service-prod
npm install --omit=dev --prefix live-service-prod
npm install --omit=dev --prefix gateway-prod
pm2 reload ecosystem.config.js
pm2 save