-
Notifications
You must be signed in to change notification settings - Fork 1
295 lines (245 loc) · 9.74 KB
/
ci.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
name: CI
on: push
env:
PROJECT_ID: ${{ secrets.GCR_PROJECT }}
PROJECT_ID_PRODUCTION: ${{ secrets.GCR_PROJECT_PRODUCTION }}
RUN_REGION: europe-north1
REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME: get-a-room
NODE_BACKEND_CLOUD_RUN_SERVICE_NAME: get-a-room-node-backend
jobs:
check-style:
name: Check code style
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run check-style
frontend-build:
name: Build frontend
runs-on: ubuntu-latest
needs: check-style
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run build:ci
env:
REACT_APP_SERVER_KEY: "${{ github.ref == 'refs/heads/main' && secrets.REACT_FRONTEND_VAPID_KEY_PRODUCTION || secrets.REACT_FRONTEND_VAPID_KEY_STAGING }}"
- uses: actions/upload-artifact@main
with:
name: frontend-build
path: frontend/build
frontend-test:
name: Test frontend
runs-on: ubuntu-latest
needs: frontend-build
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run test:ci
frontend-deploy-staging:
name: Deploy frontend to staging
if: github.ref == 'refs/heads/dev'
needs: frontend-test
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
# Checks out the repository
- name: Checkout Repo
uses: actions/checkout@main
# Downloads the archived build folder into the .docker/.docker-staging directory
- name: Download Artifact
uses: actions/download-artifact@main
with:
name: frontend-build
path: frontend/.docker/.docker-staging/build
- name: Setup gcloud CLI
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCR_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
- name: Use gcloud CLI
run: gcloud info
# Pushes the .docker/.docker-staging directory to Google Cloud Build to build the Docker image and save it to Google Cloud Registry
- name: Build & Push React frontend to Container registry
run: |-
gcloud builds submit \
--quiet \
--tag "gcr.io/$PROJECT_ID/$REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA"
working-directory: frontend/.docker/.docker-staging
# Deploy image to Cloud Run
- name: Deploy React frontend to Cloud Run
run: |-
gcloud run deploy "$REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME" \
--quiet \
--region "$RUN_REGION" \
--image "gcr.io/$PROJECT_ID/$REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA" \
--platform "managed" \
--allow-unauthenticated
frontend-deploy-prod:
name: Deploy frontend to prod
if: github.ref == 'refs/heads/main'
needs: frontend-test
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
# Checks out the repository
- name: Checkout Repo
uses: actions/checkout@main
# Downloads the archived build folder into the .docker/.docker-prod directory
- name: Download Artifact
uses: actions/download-artifact@main
with:
name: frontend-build
path: frontend/.docker/.docker-prod/build
- name: Setup gcloud CLI
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCR_SA_KEY_PRODUCTION }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
- name: Use gcloud CLI
run: gcloud info
# Pushes the .docker/.docker-prod directory to Google Cloud Build to build the Docker image and save it to Google Cloud Registry
- name: Build & Push React frontend to Container registry
run: |-
gcloud builds submit \
--quiet \
--tag "gcr.io/$PROJECT_ID_PRODUCTION/$REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA"
working-directory: frontend/.docker/.docker-prod
# Deploy image to Cloud Run
- name: Deploy React frontend to Cloud Run
run: |-
gcloud run deploy "$REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME" \
--quiet \
--region "$RUN_REGION" \
--image "gcr.io/$PROJECT_ID_PRODUCTION/$REACT_FRONTEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA" \
--platform "managed" \
--allow-unauthenticated
backend-build:
name: Build backend
needs: check-style
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run lint:ci
- run: npm run build
- uses: actions/upload-artifact@main
with:
name: backend-build
path: backend/build
backend-test:
name: Test backend
needs: backend-build
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@main
with:
node-version: 16
cache: npm
- run: npm ci
- run: npm run test:ci
backend-deploy-staging:
name: Deploy backend to staging
if: github.ref == 'refs/heads/dev'
needs: backend-test
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
# Checks out the repository
- name: Checkout Repo
uses: actions/checkout@main
- name: Setup gcloud CLI
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCR_SA_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
- name: Use gcloud CLI
run: gcloud info
# Pushes the Nodejs codes to Google Cloud Build to build the Docker image and save it to Google Cloud Registry
- name: Build and push Node backend to Container registry
run: |-
gcloud builds submit \
--quiet \
--tag "gcr.io/$PROJECT_ID/$NODE_BACKEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA"
# Deploy Node backend image to Cloud Run
- name: Deploy Node backend to Cloud Run
run: |-
gcloud run deploy $NODE_BACKEND_CLOUD_RUN_SERVICE_NAME \
--quiet \
--region "$RUN_REGION" \
--image "gcr.io/$PROJECT_ID/$NODE_BACKEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA" \
--platform "managed" \
--allow-unauthenticated
backend-deploy-prod:
name: Deploy backend to prod
if: github.ref == 'refs/heads/main'
needs: backend-test
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
# Checks out the repository
- name: Checkout Repo
uses: actions/checkout@main
- name: Setup gcloud CLI
uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.GCR_SA_KEY_PRODUCTION }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
- name: Use gcloud CLI
run: gcloud info
# Pushes the Nodejs codes to Google Cloud Build to build the Docker image and save it to Google Cloud Registry
- name: Build and push Node backend to Container registry
run: |-
gcloud builds submit \
--quiet \
--tag "gcr.io/$PROJECT_ID_PRODUCTION/$NODE_BACKEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA"
# Deploy Node backend image to Cloud Run
- name: Deploy Node backend to Cloud Run
run: |-
gcloud run deploy $NODE_BACKEND_CLOUD_RUN_SERVICE_NAME \
--quiet \
--region "$RUN_REGION" \
--image "gcr.io/$PROJECT_ID_PRODUCTION/$NODE_BACKEND_CLOUD_RUN_SERVICE_NAME:$GITHUB_SHA" \
--platform "managed" \
--allow-unauthenticated