-
Notifications
You must be signed in to change notification settings - Fork 2
406 lines (383 loc) Β· 14.8 KB
/
build.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
name: π Deploy to OpenShift
concurrency:
group: deploy-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
USER: ${{ github.actor }}
# Number of days in Advance to warn of SSL certificate expiry
SSL_EXPIRY_NOTICE_DAYS: 15
# Skip builds for faster deployments / testing ("YES" or build)
SKIP_BUILDS: "YES"
SKIP_DEPLOY: "NO"
# Clean builds before deployments will delete all resources (other than backups)
# Select "YES" or allow collisions and PVC persistence
CLEAN_BUILDS: "YES"
CLEAN_PVC: "NO" # Careful, this one wil delete all PVCs, including backups
BUILD_ID: ${{ github.event.number }}
INSPECT_JOB_URL: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
on:
schedule:
- cron: "0 3 * * 6"
push:
branches:
- e66ac2-prod
# - dev
# - test
# - prod
pull_request:
branches:
- e66ac2-prod
# - dev
# - test
# - prod
workflow_call:
secrets:
ARTIFACTORY_PASSWORD:
required: true
ARTIFACTORY_USER:
required: true
DB_USER:
required: true
DB_PASSWORD:
required: true
ARTIFACTORY_URL:
required: true
ARTIFACTORY_EMAIL:
required: true
ROCKETCHAT_WEBHOOK_URL:
required: true
jobs:
#Print variables for logging and debugging purposes
checkEnv:
name: π Environment Check
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
outputs: # Define the output parameter
APP_HOST_URL: ${{ env.APP_HOST_URL }}
CLEAN_PVC: ${{ env.CLEAN_PVC }}
APP_NAME: ${{ env.APP_NAME }}
DEPLOY_NAMESPACE: ${{ github.ref_name }}
IMAGE_REPO_DOMAIN: ${{ env.IMAGE_REPO_DOMAIN }}
IMAGE_PULL_SECRET_NAME: ${{ env.IMAGE_PULL_SECRET_NAME }}
IMAGE_REPO_URL: ${{ env.IMAGE_REPO_URL }}
BUILD_NAMESPACE: ${{ github.ref_name }}
DB_USER: ${{ env.DB_USER }}
DB_SERVICE: ${{ env.DB_SERVICE }}
DB_NAME: ${{ env.DB_NAME }}
SECRET_DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
DB_HEALTH_QUERY: ${{ env.DB_HEALTH_QUERY }}
WEB_NAME: ${{ env.WEB_NAME }}
WEB_IMAGE: ${{ env.WEB_IMAGE }}
DB_HOST: ${{ env.DB_HOST }}
DB_PORT: ${{ env.DB_PORT }}
DB_IMAGE: ${{ env.DB_IMAGE }}
PHP_NAME: ${{ env.PHP_NAME }}
CRON_NAME: ${{ env.CRON_NAME }}
CRON_IMAGE: ${{ env.CRON_IMAGE}}
REDIS_IMAGE: ${{ env.REDIS_IMAGE }}
REDIS_NAME: ${{ env.REDIS_NAME }}
REDIS_REPLICAS: ${{ env.REDIS_REPLICAS }}
DB_INIT_FILE_LOCATION: ${{ env.DB_INIT_FILE_LOCATION }}
DB_BACKUP_DEPLOYMENT_NAME: ${{ env.DB_BACKUP_DEPLOYMENT_NAME }}
DB_BACKUP_DEPLOYMENT_FULL_NAME: ${{ env.DB_BACKUP_DEPLOYMENT_FULL_NAME }}
BACKUP_IMAGE: ${{ env.BACKUP_IMAGE }}
BACKUP_HELM_CHART: ${{ env.BACKUP_HELM_CHART }}
CLEAN_BUILDS: ${{ env.CLEAN_BUILDS }}
SKIP_BUILDS: ${{ env.SKIP_BUILDS }}
SKIP_DEPLOY: ${{ env.SKIP_DEPLOY }}
steps:
- name: π€ Checkout Target Branch
uses: actions/checkout@v4
with:
ref: ${{ github.ref_name }}
sparse-checkout: |
openshift/config/mariadb
.env.example
.env.example.versions
- name: Setup Env Vars
id: dotenv
uses: falti/dotenv-action@v1
with:
path: .env.example
export-variables: true
keys-case: upper
- name: Setup Env Version Vars
id: dotenv_versions
uses: falti/dotenv-action@v1
with:
path: .env.example.versions
export-variables: true
keys-case: upper
- name: Set APP_HOST_URL
run: |
if [ -n "${{ vars.APP_HOST_URL }}" ]; then
echo "Using environment-specific APP_HOST_URL from GitHub Environment"
echo "APP_HOST_URL=${{ vars.APP_HOST_URL }}" >> $GITHUB_ENV
else
echo "Using default APP_HOST_URL from .env.example"
fi
- name: Print Env Vars
run: |
echo Deploying ${{ env.PROJECT }} > ${{ env.APP_NAME }} on ${{ github.ref_name }}
echo "-----------------------"
echo URL: https://${{ env.APP_NAME }}-${{ github.ref_name }}.apps.silver.devops.gov.bc.ca
echo DB service/database: ${{ env.DB_SERVICE }}/${{ env.DB_NAME }}
notifystart:
name: π« Notify
needs:
[
checkEnv
]
if: always()
runs-on: ubuntu-latest
steps:
- name: π« Send Notification
uses: muinmomin/webhook-action@v1.0.0
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_HOST_URL }}
with:
url: ${{ secrets.ROCKETCHAT_WEBHOOK_URL }}
data: >
{
"emoji": ":rocket:",
"text": "Deployment initiated to: ${{ github.ref_name }}",
"attachments": [{
"title": "View Job on GitHub",
"title_link": "${{ env.INSPECT_JOB_URL }}"
}]
}
setup-oc:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
# Clean up resources if CLEAN_BUILDS is set to "YES"
call-cleanup-workflow:
name: π§ΉοΈ Clean-up
uses: ./.github/workflows/cleanup.yml
secrets: inherit
needs: [checkEnv]
if: needs.checkEnv.outputs.CLEAN_BUILDS == 'YES'
with:
APP_NAME: ${{ needs.checkEnv.outputs.APP_NAME }}
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_HOST_URL }}
DEPLOY_NAMESPACE: ${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}
DB_SERVICE: ${{ needs.checkEnv.outputs.DB_SERVICE }}
WEB_NAME: ${{ needs.checkEnv.outputs.WEB_NAME }}
PHP_NAME: ${{ needs.checkEnv.outputs.PHP_NAME }}
CRON_NAME: ${{ needs.checkEnv.outputs.CRON_NAME }}
REDIS_NAME: ${{ needs.checkEnv.outputs.REDIS_NAME }}
DB_BACKUP_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.DB_BACKUP_DEPLOYMENT_NAME }}
CLEAN_PVC: ${{ needs.checkEnv.outputs.CLEAN_PVC }}
# Build Images and deploy to JFrog
db:
name: π¨ DB
needs: [checkEnv]
uses: ./.github/workflows/db.yml
secrets: inherit
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
with:
DB_IMAGE: ${{ needs.checkEnv.outputs.DB_IMAGE }}
php:
name: π¨ PHP
needs: [checkEnv]
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
uses: ./.github/workflows/php.yml
secrets: inherit
cron:
name: π¨ Cron
needs: [checkEnv]
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
uses: ./.github/workflows/cron.yml
secrets: inherit
web:
name: π¨ Web
needs: [checkEnv]
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
uses: ./.github/workflows/web.yml
secrets: inherit
build:
name: π¨ App
needs: [checkEnv, php]
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
uses: ./.github/workflows/performance.yml
secrets: inherit
call-deploy-workflow:
name: π Deploy
uses: ./.github/workflows/deploy.yml
secrets: inherit
needs: [checkEnv, call-cleanup-workflow, db, php, cron, build, web]
if: |
(always() && needs.checkEnv.outputs.SKIP_DEPLOY == 'NO') &&
needs.checkEnv.result == 'success' &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
CLEAN_PVC: ${{ needs.checkEnv.outputs.CLEAN_PVC }}
APP_NAME: ${{ needs.checkEnv.outputs.APP_NAME }}
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_HOST_URL }}
SITE_URL: "https://${{ needs.checkEnv.outputs.APP_HOST_URL }}"
WEB_NAME: ${{ needs.checkEnv.outputs.WEB_NAME }}
WEB_IMAGE: ${{ needs.checkEnv.outputs.WEB_IMAGE }}
PHP_NAME: ${{ needs.checkEnv.outputs.PHP_NAME }}
DB_IMAGE: ${{ needs.checkEnv.outputs.DB_IMAGE }}
DB_HOST: ${{ needs.checkEnv.outputs.DB_HOST }}
DB_USER: ${{ needs.checkEnv.outputs.DB_USER }}
DB_PORT: ${{ needs.checkEnv.outputs.DB_PORT }}
DB_SERVICE: ${{ needs.checkEnv.outputs.DB_SERVICE }}
DB_NAME: ${{ needs.checkEnv.outputs.DB_NAME }}
DB_INIT_FILE_LOCATION: ${{ needs.checkEnv.outputs.DB_INIT_FILE_LOCATION }}
DB_HEALTH_QUERY: ${{ needs.checkEnv.outputs.DB_HEALTH_QUERY }}
DB_BACKUP_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.DB_BACKUP_DEPLOYMENT_NAME }}
DB_BACKUP_DEPLOYMENT_FULL_NAME: ${{ needs.checkEnv.outputs.DB_BACKUP_DEPLOYMENT_FULL_NAME }}
BACKUP_IMAGE: ${{ needs.checkEnv.outputs.BACKUP_IMAGE }}
BACKUP_HELM_CHART: ${{ needs.checkEnv.outputs.BACKUP_HELM_CHART }}
CRON_IMAGE: ${{ needs.checkEnv.outputs.CRON_IMAGE }}
CRON_NAME: ${{ needs.checkEnv.outputs.CRON_NAME }}
REDIS_IMAGE: ${{ needs.checkEnv.outputs.REDIS_IMAGE }}
REDIS_NAME: ${{ needs.checkEnv.outputs.REDIS_NAME }}
REDIS_REPLICAS: ${{ needs.checkEnv.outputs.REDIS_REPLICAS }}
BUILD_NAMESPACE: ${{ needs.checkEnv.outputs.BUILD_NAMESPACE }}
DEPLOY_NAMESPACE: ${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}
IMAGE_REPO_URL: ${{ needs.checkEnv.outputs.IMAGE_REPO_URL }}
IMAGE_REPO_DOMAIN: ${{ needs.checkEnv.outputs.IMAGE_REPO_DOMAIN }}
IMAGE_PULL_SECRET_NAME: ${{ needs.checkEnv.outputs.IMAGE_PULL_SECRET_NAME }}
lighthouse-check:
name: π¦ Audit
runs-on: ubuntu-latest
needs: [checkEnv, call-deploy-workflow]
environment: ${{ github.ref_name }}
outputs:
LHRESULT: ${{ steps.lighthouse.outputs.LHRESULT }}
SSL_EXPIRY_DAYS: ${{ steps.ssl-test.outputs.SSL_EXPIRY_DAYS }}
if: |
always() &&
(
needs.call-deploy-workflow.result == 'success' ||
needs.checkEnv.outputs.SKIP_DEPLOY == 'YES'
) &&
!contains(needs.*.result, 'failure')
steps:
- uses: actions/checkout@v4
- run: mkdir -p tmp/artifacts
- name: Install Puppeteer and Lighthouse and SSL Checker
run: npm install puppeteer lighthouse node-fetch ssl-checker
- name: Install dependencies
run: sudo apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
- name: Setup Chrome
id: setup-chrome
uses: browser-actions/setup-chrome@latest
with:
install-dependencies: false
- name: Run Lighthouse Tests
id: lighthouse
run: |
LHRESULT=$(node openshift/config/lighthouse/lighthouse-auth.js)
echo "LHRESULT=$LHRESULT" >> $GITHUB_OUTPUT
if echo "$LHRESULT" | grep -qi "error"; then
echo "Error detected in Lighthouse Test Result: $LHRESULT"
exit 1
fi
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_HOST_URL }}
TESTER_USERNAME: ${{ secrets.TESTER_USERNAME }}
TESTER_PASSWORD: ${{ secrets.TESTER_PASSWORD }}
- name: Run SSL Certificate Test
id: ssl-test
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_HOST_URL }}
run: |
# Perform SSL check
SSL_EXPIRY_DAYS=$(node -e "
const sslChecker = require('ssl-checker');
sslChecker(process.env.APP_HOST_URL, { method: 'GET', port: 443 })
.then(info => console.log(info.daysRemaining))
.catch(err => console.error(err));
")
echo "SSL_EXPIRY_DAYS=$SSL_EXPIRY_DAYS" >> $GITHUB_OUTPUT
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: lighthouse-artifacts
path: |
/home/runner/work/performance/performance/*.png
/home/runner/work/performance/performance/*.md
notify:
name: π« Notify
needs:
[
checkEnv,
web,
build,
cron,
php,
db,
call-cleanup-workflow,
call-deploy-workflow,
lighthouse-check
]
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download artifacts
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: lighthouse-artifacts
path: artifacts
- name: Set Emoji for Notification Status Icon
id: notification-emoji
run: |
if [[ "${{ needs.lighthouse-check.result }}" == "success" ]]; then
`echo "EMOJI=:rocket:" >> $GITHUB_OUTPUT`
else
`echo "EMOJI=:boom:" >> $GITHUB_OUTPUT`
fi
- name: Set Emoji for SSL Status Icon
id: ssl-status-emoji
run: |
if [[ "${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }}" -lt ${{ env.SSL_EXPIRY_NOTICE_DAYS }} ]]; then
echo "SSL_TEST_RESULT=:warning: Warning! SSL Certificate EXPIRES in ${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }} days." >> $GITHUB_ENV
else
echo "SSL_TEST_RESULT=:white_check_mark: SSL Certificate expires in ${{ needs.lighthouse-check.outputs.SSL_EXPIRY_DAYS }} days." >> $GITHUB_ENV
fi
- name: π« Send Notification
uses: muinmomin/webhook-action@v1.0.0
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP_HOST_URL }}
with:
url: ${{ secrets.ROCKETCHAT_WEBHOOK_URL }}
data: >
{
"emoji": "${{ steps.notification-emoji.outputs.EMOJI }}",
"text": "Deployment to: ${{ github.ref_name }}, status: ${{ needs.call-deploy-workflow.result }}",
"attachments": [{
"title": "View Job on GitHub",
"title_link": "${{ env.INSPECT_JOB_URL }}",
"fields": [{
"title": "Verify Deployment",
"value": "Verify that the site still works and updates have been completed (Admin access required) https://${{ needs.checkEnv.outputs.APP_HOST_URL }}/admin/index.php"
},{
"title": "Build DB: ${{ needs.db.result }}"
},{
"title": "Build PHP: ${{ needs.php.result }}"
},{
"title": "Build Cron: ${{ needs.cron.result }}"
},{
"title": "Build Web: ${{ needs.web.result }}"
},{
"title": "Build Performance App: ${{ needs.build.result }}"
},{
"title": "Cleanup Resources: ${{ needs.call-cleanup-workflow.result }}"
},{
"title": "Deploy to OpenShift: ${{ needs.call-deploy-workflow.result }}"
},{
"title": "Lighthouse Test Results:",
"value": "${{ needs.lighthouse-check.outputs.LHRESULT }}"
},{
"title": "SSL Certificate Expiry:",
"value": "${{ env.SSL_TEST_RESULT }}"
}]
}]
}