-
Notifications
You must be signed in to change notification settings - Fork 6
330 lines (273 loc) · 9.44 KB
/
cicd.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
#
# Example GitHub Actions config that drives UW-IT AXD2 integration and deployment
#
# Preconditions:
#
# 1) Application docker build is based on django-container
#
# 2) Application test suite is kicked off in docker/test.sh
#
# 3) Application repo has access to the two secrets
# at https://github.com/organizations/uw-it-aca/settings/secrets:
#
# GH_AUTH_TOKEN: Grants access to private flux deployment repo
# GCP_JSON_KEY: Grants access to Google Cloud Registry
#
# To adapt this config file to a specific django project:
#
# 1) Set RELEASE_NAME suitable for deployment to k8s. RELEASE_NAME must
# match the "repo" value in docker/*-values.yml.
#
# 2) Set DJANGO_APP to the name of the django project name/directory.
#
# 3) Verify that the lists of branches for push/pull_request is appropriate,
# and add other branch names if needed. Additional branch names must
# also have steps defined in the deploy job
#
# 4) Confirm that the build steps are suitable. Likely they are, but
# some projects have an intermediate build step that could benefit
# from caching, so it may be useful to augment the build steps.
#
---
name: Build, Test and Deploy
env:
# Release name must match "repo" value in docker/*-values.yml
RELEASE_NAME: myuw
DJANGO_APP: myuw
CONF_PATH: myuw
COVERAGE_DJANGO_VERSION: '4.2'
COVERAGE_PYTHON_VERSION: '3.10'
# Be sure that branches defined here have corresponding steps
# defined in the "deploy" job
on:
push:
branches: [main, master, qa, develop, fix/MUWM-5350]
pull_request:
branches: [main, master, qa, develop, fix/MUWM-5350]
types: [opened, reopened, synchronize]
release:
branches: [main, master]
types: [published]
jobs:
context:
runs-on: ubuntu-22.04
outputs:
commit_hash: ${{ steps.context.outputs.commit_hash }}
git_repo_branch: ${{ steps.context.outputs.git_repo_branch }}
image_tag: ${{ steps.context.outputs.image_tag }}
steps:
- name: Set up Context
id: context
uses: uw-it-aca/actions/cicd-context@main
with:
release_name: ${{ env.RELEASE_NAME }}
build:
runs-on: ubuntu-22.04
needs: context
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Run Python Linters
uses: uw-it-aca/actions/python-linters@main
with:
app_name: ${DJANGO_APP}
exclude_paths: 'migrations'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-$(echo ${{ hashFiles('Dockerfile') }} | head -c 16)
restore-keys: |
${{ runner.os }}-buildx-
- name: Disable Vue Devtools
if: endsWith(github.ref, '/main') || endsWith(github.ref, '/master')
run: echo "VUE_DEVTOOLS=False" >> $GITHUB_ENV
- name: Enable Vue Devtools
if: ${{ !(endsWith(github.ref, '/main') || endsWith(github.ref, '/master')) }}
run: echo "VUE_DEVTOOLS=True" >> $GITHUB_ENV
- name: Build App Image
uses: docker/build-push-action@v4
with:
target: app-container
tags: ${{ needs.context.outputs.image_tag }}
push: false
load: true
build-args: VUE_DEVTOOLS=${{ env.VUE_DEVTOOLS }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Build Test Image
uses: docker/build-push-action@v4
with:
target: app-test-container
tags: app-test-container
push: false
load: true
- name: Start Memcached
run: docker run -d -h memcached -p 11211:11211 memcached:1.6-alpine
- name: Run Tests in Image
id: tests
shell: bash
run: >-
docker run -u root -t
-v ${PWD}:/coverage
-e DJANGO_APP="$DJANGO_APP"
-e ENV="localdev"
-e AUTH="SAML_MOCK"
app-test-container
bash -c ". ./docker/test_python.sh"
- name: Push Image to Repository
if: github.event_name == 'push'
uses: uw-it-aca/actions/gcr-push@main
with:
image_tag: ${{ needs.context.outputs.image_tag }}
gcp_json_key: ${{ secrets.GCP_JSON_KEY }}
- uses: actions/upload-artifact@v3
with:
name: python-coverage
path: .coverage.*
outputs:
image_tag: ${{ steps.cicd.outputs.image_tag }}
eslint:
runs-on: ubuntu-22.04
container:
image: node:20
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install packages
run: npm install .
- name: Run eslint
run: ./node_modules/.bin/eslint myuw_vue/ --ext .vue
jest-cypress:
runs-on: ubuntu-22.04
container:
image: cypress/browsers:node14.16.0-chrome90-ff88
# this image works. later images failed
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install packages
run: npm install .
- name: Run jest
run: ./node_modules/.bin/jest --ci --coverage
- name: Move jest lcov report
shell: bash
run: |
ls -la coverage
mv coverage/lcov.info lcov-jest.info
rm -rf coverage
- name: Run cypress
run: ./node_modules/.bin/cypress run-ct
- name: Merge cypress and jest lcov reports
shell: bash
run: |
apt install lcov -y
lcov -a lcov-jest.info -a coverage/lcov.info -o lcov.info
- uses: actions/upload-artifact@v3
with:
name: jest-cypress-coverage
path: lcov.info
collect-coverage:
needs: [build, jest-cypress]
runs-on: ubuntu-22.04
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: python-coverage
- uses: actions/download-artifact@v3
with:
name: jest-cypress-coverage
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Set up Ruby 2.6
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Record Test Results
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
gem install coveralls-lcov
python -m pip install --upgrade pip coverage coveralls==3.3.1
coverage combine
coveralls-lcov -v -n lcov.info > js-coverage.json
coveralls --merge=js-coverage.json
deploy:
if: github.event_name == 'push'
needs: [context, build, eslint, jest-cypress]
outputs:
context: ${{ steps.context.outputs.context }}
runs-on: ubuntu-22.04
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Deployment Pipeline
if: >-
contains(fromJSON('["main", "master", "qa"]'),
needs.context.outputs.git_repo_branch)
uses: uw-it-aca/actions/cicd-deploy@main
with:
release_name: ${{ env.RELEASE_NAME }}
commit_hash: ${{ needs.context.outputs.commit_hash }}
git_repo_branch: ${{ needs.context.outputs.git_repo_branch }}
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
- name: Deploy Develop Branch
if: needs.context.outputs.git_repo_branch == 'develop'
uses: uw-it-aca/actions/cicd-deploy@main
with:
release_name: ${{ env.RELEASE_NAME }}
commit_hash: ${{ needs.context.outputs.commit_hash }}
git_repo_branch: ${{ needs.context.outputs.git_repo_branch }}
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
app_instance: dev
- name: Deploy Vue Branch
if: needs.context.outputs.git_repo_branch == 'fix/MUWM-5350'
uses: uw-it-aca/actions/cicd-deploy@main
with:
release_name: ${{ env.RELEASE_NAME }}
commit_hash: ${{ needs.context.outputs.commit_hash }}
git_repo_branch: ${{ needs.context.outputs.git_repo_branch }}
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
app_instance: vue
- name: 'Surface context from executed build step'
id: context
shell: bash
run: echo "context=$(< ${CONTEXT_FILENAME})" >> $GITHUB_OUTPUT
housekeeping:
if: github.event_name == 'push' &&
(endsWith(github.ref, '/main') || endsWith(github.ref, '/master') ||
endsWith(github.ref, '/qa') || endsWith(github.ref, '/develop') ||
endsWith(github.ref, '/fix/MUWM-5350'))
needs: [context, build, deploy]
runs-on: ubuntu-22.04
steps:
- name: House Keeping
uses: uw-it-aca/actions/cicd-housekeeping@main
with:
release_name: ${{ env.RELEASE_NAME }}
gh_auth_token: ${{ secrets.GH_AUTH_TOKEN }}
registry_password: ${{ secrets.GCP_JSON_KEY }}
context: ${{ needs.deploy.outputs.context }}