-
Notifications
You must be signed in to change notification settings - Fork 12
499 lines (411 loc) · 12.3 KB
/
build.js.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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
name: Build Bailo Image
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build_backend:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
# Clone repository
- uses: actions/checkout@v3
# Setup BuildX
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build backend image
uses: docker/build-push-action@v3
with:
context: backend
file: backend/Dockerfile
tags: bailo_backend:latest
cache-from: type=gha,scope=backend
cache-to: type=gha,mode=max,scope=backend
outputs: type=docker,dest=/tmp/bailo_backend.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bailo_backend
path: /tmp/bailo_backend.tar
build_frontend:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
# Clone repository
- uses: actions/checkout@v3
# Setup BuildX
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build frontend image
uses: docker/build-push-action@v3
with:
context: frontend
file: frontend/Dockerfile
tags: bailo_frontend:latest
cache-from: type=gha,scope=frontend
cache-to: type=gha,mode=max,scope=frontend
outputs: type=docker,dest=/tmp/bailo_frontend.tar
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bailo_frontend
path: /tmp/bailo_frontend.tar
unit_testing:
runs-on: ubuntu-latest
steps:
# Clone repository
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.17.1
cache: "npm"
# Install dependencies
- run: npm ci
# Create certs
- run: sudo chown -R runner:docker backend/certs
- run: npm run certs
# Run unit tests
- run: npm run test
style:
runs-on: ubuntu-latest
steps:
# Clone repository
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.17.1
cache: "npm"
# Install dependencies
- run: npm ci
# Run style checks
- run: npm run check-style
- run: npm run lint
kubernetes:
needs: [build_backend, build_frontend]
runs-on: ubuntu-latest
steps:
# Clone repository
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.17.1
cache: "npm"
# Setup BuildX
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Get Bailo Docker image
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: bailo_backend
path: /tmp
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: bailo_frontend
path: /tmp
- name: Start minikube
uses: medyagh/setup-minikube@master
- name: List Cluster
run: kubectl get pods -A
- name: Load docker image to minikube
run: |
eval $(minikube -p minikube docker-env)
docker load -i /tmp/bailo_backend.tar
docker load -i /tmp/bailo_frontend.tar
# Install dependencies
- run: npm ci
# Create certs
- run: sudo chown -R runner:docker backend/certs
- run: npm run certs
# Add bailo NodePort
- name: Create NodePort Config
run: |
cat << EOT >> infrastructure/helm/bailo/templates/nodePort.yaml
---
apiVersion: v1
kind: Service
metadata:
name: node-port
spec:
type: NodePort
ports:
- port: {{ .Values.nginxAuth.port }}
targetPort: {{ .Values.nginxAuth.port }}
selector:
name: nginx
EOT
# Create local.yaml
- name: Create local.yaml
run: |
cat << EOT >> infrastructure/helm/bailo/local.yaml
---
# Instance Settings
securityContext:
runAsUser: 1002
config:
ui:
banner:
enabled: "true"
text: "BAILO TEST"
build:
environment: img
# Bailo
image:
frontendRepository: "bailo_frontend"
frontendTag: latest
backendRepository: "bailo_backend"
backendTag: latest
# Used for k8s not openshift
ingress:
enabled: false
route:
enabled: false
appPublicRoute: localhost
mongodb:
architecture: standalone
auth:
passwords:
- MongoDBPassword
usernames:
- bailo_user
EOT
- name: Set Bailo image pull policy to Never
run: sed -i 's/{{ .Values.image.pullPolicy }}/Never/g' infrastructure/helm/bailo/templates/bailo/bailo.deployment.yaml
- name: HELM update dependency update
working-directory: ./infrastructure/helm/bailo
run: helm dependency update
- name: HELM deploy to minikube
working-directory: ./infrastructure/helm/bailo
run: helm install --values ./local.yaml bailo .
- name: Sleep for 90 seconds
run: sleep 90s
shell: bash
- name: List Pods
run: kubectl get pods
- name: List Services
run: kubectl get services
- name: HELM test Bailo
working-directory: ./infrastructure/helm/bailo
run: helm test bailo
- name: Test Bailo URL
run: |
minikube service list
echo "---------------curl connect to bailo---------------"
curl $(minikube service node-port --url)
# Run Cypress integration tests
#- run: CYPRESS_BASE_URL=$(minikube service node-port --url) npm run cy:run
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots-k8s
path: cypress/screenshots
# - uses: actions/upload-artifact@v3
# if: always()
# with:
# name: cypress-videos
# path: cypress/videos
- name: Print application logs
if: always()
run: kubectl logs -l app.kubernetes.io/instance=bailo --tail=-1
end_to_end:
needs: [build_backend, build_frontend]
runs-on: ubuntu-latest
steps:
# Clone repository
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.17.1
cache: "npm"
# Setup BuildX
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Get Bailo Docker images
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: bailo_backend
path: /tmp
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: bailo_frontend
path: /tmp
- name: Load image
run: |
docker load --input /tmp/bailo_frontend.tar
docker load --input /tmp/bailo_backend.tar
docker image ls -a
rm -rf /tmp/bailo_frontend.tar /tmp/bailo_backend.tar
# Create logs directory
- run: mkdir logs
# Install dependencies
- run: npm ci
# Create certs
- run: sudo chown -R runner:docker backend/certs
- run: npm run certs
# Configure application
- name: Configure Bailo
run: |
cat <<EOT >> backend/config/local.cjs
module.exports = {
minio: {
accessKey: 'minioadmin',
secretKey: 'minioadmin',
},
smtp: {
auth: {
user: 'mailuser',
pass: 'mailpass',
},
tls: {
rejectUnauthorized: false,
},
},
logging: {
file: {
path: '/home/runner/work/Bailo/Bailo/logs/out.log',
},
},
}
EOT
- run: docker compose -f docker-compose-prod.yml up -d
# wait for app to start
- run: |
chmod +x ./backend/src/scripts/waitForIt.sh
./backend/src/scripts/waitForIt.sh localhost:8080 -t 10
# wait for mongo to start
- run: |
chmod +x ./backend/src/scripts/waitForIt.sh
./backend/src/scripts/waitForIt.sh localhost:27017 -t 10
- uses: cypress-io/github-action@v5
with:
wait-on: 'http://localhost:8080/api/v2/config/ui'
working-directory: ./frontend
install: false
spec: cypress/e2e/bailo/**/*
- uses: actions/upload-artifact@v3
if: failure()
with:
name: cypress-screenshots-e2e
path: frontend/cypress/screenshots
# - uses: actions/upload-artifact@v3
# if: always()
# with:
# name: cypress-videos
# path: cypress/videos
- name: Dump docker compose logs
if: always()
run: docker compose logs > logs/stack.log
- name: Docker Compose Logs
if: always()
run: cat logs/stack.log
- uses: actions/upload-artifact@v3
if: always()
with:
name: logs
path: logs
integration_python:
needs: [build_backend, build_frontend]
runs-on: ubuntu-latest
steps:
# Clone repository
- uses: actions/checkout@v3
- name: Use Node.js 18
uses: actions/setup-node@v3
with:
node-version: 18.17.1
cache: "npm"
# Setup BuildX
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Get Bailo Docker images
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: bailo_backend
path: /tmp
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: bailo_frontend
path: /tmp
- name: Load image
run: |
docker load --input /tmp/bailo_frontend.tar
docker load --input /tmp/bailo_backend.tar
docker image ls -a
# Create logs directory
- run: mkdir logs
# Install dependencies
- run: npm ci
# Create certs
- run: sudo chown -R runner:docker backend/certs
- run: npm run certs
# Configure application
- name: Configure Bailo
run: |
cat <<EOT >> backend/config/local.cjs
module.exports = {
minio: {
accessKey: 'minioadmin',
secretKey: 'minioadmin',
},
smtp: {
auth: {
user: 'mailuser',
pass: 'mailpass',
},
tls: {
rejectUnauthorized: false,
},
},
logging: {
file: {
path: '/home/runner/work/Bailo/Bailo/logs/out.log',
},
},
}
EOT
- run: docker compose -f docker-compose-prod.yml up -d
# wait for app to start
- run: |
chmod +x ./backend/src/scripts/waitForIt.sh
./backend/src/scripts/waitForIt.sh localhost:8080 -t 10
# wait for mongo to start
- run: |
chmod +x ./backend/src/scripts/waitForIt.sh
./backend/src/scripts/waitForIt.sh localhost:27017 -t 10
# Setup python
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
# Install dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
cd lib/python
python -m pip install -e .[test]
# Run tests
- name: Test with pytest
run: |
cd lib/python
python -m pytest -m integration
- name: Dump docker compose logs
if: always()
run: docker compose logs > logs/stack.log
- name: Docker Compose Logs
if: always()
run: cat logs/stack.log
- uses: actions/upload-artifact@v3
if: always()
with:
name: logs
path: logs