-
Notifications
You must be signed in to change notification settings - Fork 1
329 lines (309 loc) · 12.3 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
name: 🚀 Deploy to OpenShift
concurrency:
group: deploy-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
APP: moodle
USER: ${{ github.actor }}
# Skip builds for faster deployments / testing ("YES" or build)
SKIP_BUILDS: "YES"
SKIP_DEPLOY: "NO"
# Clean builds before deployments (delete all resources, other than backups) ("YES" or allow collisions)
CLEAN_BUILDS: "YES"
BUILD_ID: ${{ github.event.number }}
# BRANCH: ${{ env.BRANCH }}
BRANCH: dev
INSPECT_JOB_URL: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
BUILD_ICON_URL: https://cdn-icons-png.flaticon.com/128/5110/5110294.png
SUCCESS_ICON_URL: https://cdn-icons-png.flaticon.com/128/1356/1356479.png
FAIL_ICON_URL: https://www.flaticon.com/free-icon/rocket_6818114
on:
schedule:
- cron: "0 3 * * 6"
push:
branches:
- dev
# - test
# - prod
pull_request:
branches:
- dev
#- test
#- prod
workflow_call:
secrets:
DB_NAME:
required: true
DB_USER:
required: true
DB_PASSWORD:
required: true
ARTIFACTORY_URL:
required: true
jobs:
#Print variables for logging and debugging purposes
checkEnv:
name: 📋 Environment Check
runs-on: ubuntu-22.04
outputs: # Define the output parameter
APP: ${{ env.APP }}
BRANCH: ${{ env.BRANCH }}
DEPLOY_ENVIRONMENT: ${{ env.DEPLOY_ENVIRONMENT }}
DEPLOY_NAMESPACE: ${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ env.BRANCH }}
IMAGE_REPO: ${{ env.IMAGE_REPO }}
BUILD_NAMESPACE: ${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ env.BRANCH }}
DB_DEPLOYMENT_NAME: ${{ env.DB_DEPLOYMENT_NAME }}
WEB_DEPLOYMENT_NAME: ${{ env.WEB_DEPLOYMENT_NAME }}
WEB_IMAGE: ${{ env.WEB_IMAGE }}
DB_HOST: ${{ env.DB_HOST }}
DB_PORT: ${{ env.DB_PORT }}
DB_NAME: ${{ env.DB_NAME }}
DB_IMAGE: ${{ env.DB_IMAGE }}
PHP_DEPLOYMENT_NAME: ${{ env.PHP_DEPLOYMENT_NAME }}
CRON_NAME: ${{ env.CRON_NAME }}
CRON_IMAGE: ${{ env.CRON_IMAGE}}
REDIS_HELM_CHART: ${{ env.REDIS_HELM_CHART }}
REDIS_NAME: ${{ env.REDIS_NAME }}
REDIS_PROXY_NAME: ${{ env.REDIS_PROXY_NAME }}
REDIS_HOST: ${{ env.REDIS_HOST }}
REDIS_URL: ${{ env.REDIS_URL }}
REDIS_PORT: ${{ env.REDIS_PORT }}
REDIS_REPLICAS: ${{ env.REDIS_REPLICAS }}
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: dev
sparse-checkout: |
config/mariadb
example.env
example.versions.env
- name: Setup Env Vars
id: dotenv
uses: falti/dotenv-action@v1
with:
path: example.env
export-variables: true
keys-case: upper
- name: Setup Env Version Vars
id: dotenv_versions
uses: falti/dotenv-action@v1
with:
path: example.versions.env
export-variables: true
keys-case: upper
- name: Print Env Vars
run: |
echo Deploying ${{ env.PROJECT }} > ${{ env.APP }} on ${{ env.OPENSHIFT_DEPLOY_PROJECT }}-${{ env.BRANCH }}
echo "-----------------------"
echo URL: https://${{ env.APP }}-${{ env.DEPLOY_NAMESPACE }}-${{ env.BRANCH }}.apps.silver.devops.gov.bc.ca
# 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
moodle:
name: 🔨 Moodle
needs: [checkEnv]
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
uses: ./.github/workflows/moodle.yml
secrets: inherit
redis-proxy:
name: 🔨 Redis Proxy
needs: [checkEnv]
if: needs.checkEnv.outputs.SKIP_BUILDS == 'NO'
uses: ./.github/workflows/redis-proxy.yml
secrets: inherit
call-cleanup-workflow:
name: 🧹️ Clean-up
uses: ./.github/workflows/cleanup.yml
secrets: inherit
needs: [checkEnv, db, php, cron, moodle, web, redis-proxy]
# if: success()
if: needs.checkEnv.outputs.CLEAN_BUILDS == 'YES'
with:
APP: ${{ needs.checkEnv.outputs.APP }}
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP }}-${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}.apps.silver.devops.gov.bc.ca
BRANCH: ${{ needs.checkEnv.outputs.BRANCH }}
BUILD_NAMESPACE: ${{ needs.checkEnv.outputs.BUILD_NAMESPACE }}
DEPLOY_NAMESPACE: ${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}
DB_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.DB_DEPLOYMENT_NAME }}
WEB_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.WEB_DEPLOYMENT_NAME }}
PHP_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.PHP_DEPLOYMENT_NAME }}
CRON_NAME: ${{ needs.checkEnv.outputs.CRON_NAME }}
REDIS_NAME: ${{ needs.checkEnv.outputs.REDIS_NAME }}
call-deploy-workflow:
name: 🚀 Deploy
uses: ./.github/workflows/deploy.yml
secrets: inherit
needs: [checkEnv, db, php, cron, moodle, web, redis-proxy, call-cleanup-workflow]
if: |
(always() && needs.checkEnv.outputs.SKIP_DEPLOY == 'NO') &&
needs.checkEnv.result == 'success' &&
!contains(needs.*.result, 'failure') &&
!contains(needs.*.result, 'cancelled')
with:
DEPLOY_ENVIRONMENT: ${{ needs.checkEnv.outputs.DEPLOY_ENVIRONMENT }}
APP: ${{ needs.checkEnv.outputs.APP }}
WEB_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.WEB_DEPLOYMENT_NAME }}
WEB_IMAGE: ${{ needs.checkEnv.outputs.WEB_IMAGE }}
PHP_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.PHP_DEPLOYMENT_NAME }}
DB_IMAGE: ${{ needs.checkEnv.outputs.DB_IMAGE }}
DB_HOST: ${{ needs.checkEnv.outputs.DB_HOST }}
DB_PORT: ${{ needs.checkEnv.outputs.DB_PORT }}
DB_DEPLOYMENT_NAME: ${{ needs.checkEnv.outputs.DB_DEPLOYMENT_NAME }}
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_HELM_CHART: ${{ needs.checkEnv.outputs.REDIS_HELM_CHART }}
REDIS_NAME: ${{ needs.checkEnv.outputs.REDIS_NAME }}
REDIS_PROXY_NAME: ${{ needs.checkEnv.outputs.REDIS_PROXY_NAME }}
REDIS_PORT: ${{ needs.checkEnv.outputs.REDIS_PORT }}
REDIS_HOST: ${{ needs.checkEnv.outputs.REDIS_HOST }}
REDIS_URL: ${{ needs.checkEnv.outputs.REDIS_URL }}
REDIS_REPLICAS: ${{ needs.checkEnv.outputs.REDIS_REPLICAS }}
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP }}-${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}.apps.silver.devops.gov.bc.ca
BUILD_NAMESPACE: ${{ needs.checkEnv.outputs.BUILD_NAMESPACE }}
DEPLOY_NAMESPACE: ${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}
IMAGE_REPO: ${{ needs.checkEnv.outputs.IMAGE_REPO }}
lighthouse-check:
name: 🚦 Audit
runs-on: ubuntu-22.04
needs: [checkEnv, call-deploy-workflow]
outputs:
LHRESULT: ${{ steps.lighthouse.outputs.LHRESULT }}
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
run: npm install puppeteer lighthouse
- 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: Lighthouse
id: lighthouse
run: |
sleep 120 # Wait for the deployment to be ready
`echo "LHRESULT=$(node config/lighthouse/lighthouse-auth.js)" >> $GITHUB_OUTPUT`
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP }}-${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}.apps.silver.devops.gov.bc.ca
USERNAME: ${{ secrets.MOODLE_TESTER_USERNAME }}
PASSWORD: ${{ secrets.MOODLE_TESTER_PASSWORD }}
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: lighthouse-artifacts
path: |
/home/runner/work/moodle-nginx/moodle-nginx/*.png
/home/runner/work/moodle-nginx/moodle-nginx/*.md
notify:
name: 📫 Notify
needs:
[
checkEnv,
web,
moodle,
cron,
php,
db,
call-cleanup-workflow,
call-deploy-workflow,
lighthouse-check
]
if: always()
runs-on: ubuntu-22.04
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.call-deploy-workflow.result }}" == "success" ]]; then
`echo "EMOJI=:rocket:" >> $GITHUB_OUTPUT`
else
`echo "EMOJI=:boom:" >> $GITHUB_OUTPUT`
fi
- name: 📫 Send Notification
uses: muinmomin/[email protected]
env:
APP_HOST_URL: ${{ needs.checkEnv.outputs.APP }}-${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}.apps.silver.devops.gov.bc.ca
with:
url: ${{ secrets.ROCKETCHAT_WEBHOOK_URL }}
data: >
{
"emoji": "${{ steps.notification-emoji.outputs.EMOJI }}",
"text": "Deployment to: ${{ needs.checkEnv.outputs.DEPLOY_NAMESPACE }}, status: ${{ needs.call-deploy-workflow.result }}",
"attachments": [{
"title": "View Job on GitHub",
"title_link": "${{ env.INSPECT_JOB_URL }}",
"fields": [{
"title": "Verify Moodle",
"value": "Verify that the site still works and updates have been completed (Admin access required) [Moodle Admin](https://${{ env.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 Moodle: ${{ needs.moodle.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 }}"
}]
}]
}