generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
334 lines (292 loc) · 10.5 KB
/
merge-main.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
name: Main Merge
on:
push:
branches:
- main
paths-ignore:
- ".**"
- "**.md"
- "**.yml"
- "**.yaml"
env:
REGISTRY: ghcr.io
NAME: esra
jobs:
codeql:
name: Semantic Code Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize
uses: github/codeql-action/init@v2
with:
languages: javascript
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
# https://github.com/snyk/snyk
snyk:
name: Dependency Report
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/node@master
continue-on-error: true # To make sure that SARIF upload gets called
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --all-projects --severity-threshold=high --sarif-file-output=snyk.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: snyk.sarif
sonarcloud:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# Disable shallow clone for SonarCloud analysis
with:
fetch-depth: 0
- name: Backend Tests
run: |
cd frontend
npm ci
npm run test:cov
- name: Frontend Tests
run: |
cd frontend
npm ci
npm run test:cov
# - name: SonarCloud Scan
# uses: SonarSource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# with:
# args: >
# -Dsonar.exclusions=**/test/**,.github/**/*
# -Dsonar.organization=bcgov-sonarcloud
# -Dsonar.javascript.lcov.reportPaths=backend/coverage/lcov.info,frontend/coverage/lcov.info
# -Dsonar.cobertura.reportPaths=backend/coverage/cobertura-coverage.xml,frontend/coverage/cobertura-coverage.xml
# -Dsonar.project.monorepo.enabled=true
# -Dsonar.projectKey=greenfield-template
# -Dsonar.sources=backend,frontend
# -Dsonar.tests=backend/test,frontend/test
# https://github.com/marketplace/actions/aqua-security-trivy
trivy-backend:
name: Backend Image Report
runs-on: ubuntu-18.04
steps:
- name: Checkout code
uses: actions/checkout@v2
# Backend container scan
- name: Trivy Image Scan
uses: aquasecurity/trivy-action@0.3.0
with:
image-ref: ${{ env.REGISTRY }}/${{ github.repository }}:test-backend
ignore-unfixed: true
severity: CRITICAL
format: "sarif"
output: "trivy-results-backend.sarif"
- name: Upload Trivy results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results-backend.sarif"
# https://github.com/marketplace/actions/aqua-security-trivy
trivy-frontend:
name: Frontend Image Report
runs-on: ubuntu-18.04
steps:
- name: Checkout code
uses: actions/checkout@v2
# Frontend container scan
- name: Trivy Image Scan
uses: aquasecurity/trivy-action@0.3.0
with:
image-ref: ${{ env.REGISTRY }}/${{ github.repository }}:test-frontend
ignore-unfixed: true
severity: CRITICAL
format: "sarif"
output: "trivy-results-frontend.sarif"
- name: Upload Trivy results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results-frontend.sarif"
# https://github.com/marketplace/actions/aqua-security-trivy
trivy-repo:
name: Repository Report
runs-on: ubuntu-18.04
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@0.3.0
with:
scan-type: "fs"
ignore-unfixed: true
format: "sarif"
output: "trivy-results.sarif"
severity: "CRITICAL"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
# https://github.com/marketplace/actions/aqua-security-trivy
trivy-rhel-ubi:
name: Base Image Report
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Trivy Vulnerability Scan
uses: aquasecurity/trivy-action@0.3.0
with:
image-ref: registry.access.redhat.com/ubi8/ubi
ignore-unfixed: true
severity: CRITICAL
format: "sarif"
output: "trivy-results.sarif"
- name: Upload Trivy results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: "trivy-results.sarif"
cleanup-ghcr:
name: Cleanup Container Registry
runs-on: ubuntu-latest
steps:
# https://github.com/marketplace/actions/ghcr-io-container-cleanup
- name: Delete old packages
uses: davahome/ghcr-cleanup@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
package: ${{ github.event.repository.name }}
owner: orgs/bcgov
skip_tags: prod-frontend,prod-backend
deploy-test:
name: TEST Deployment
runs-on: ubuntu-latest
environment:
name: test
env:
ZONE: test
steps:
- uses: actions/checkout@v2
- name: Deploy
run: |
# Login to OpenShift and select project
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }}
oc project ${{ secrets.OC_NAMESPACE }}
# Clear stale images for import/replacement
if [ $(oc get is -l app=${{ env.NAME }}-${{ env.ZONE }} -o name | grep -v database | wc -l) -gt 0 ]; then
oc delete is -l app=${{ env.NAME }}-${{ env.ZONE }}
fi
# Process and apply deployment templates
oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc apply -f -
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p PROMOTE=${{ github.repository }}:${{ env.ZONE }}-backend | oc apply -f -
oc process -f .github/openshift/deploy.frontend.yml -p ZONE=${{ env.ZONE }} \
-p PROMOTE=${{ github.repository }}:${{ env.ZONE }}-frontend | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-backend -w
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-frontend -w
# Remove completed build runs, build pods and deployment pods
for p in $(oc get po | grep "Completed" | awk '{print $1}')
do
oc delete po ${p}
done
zap-backend:
name: Backend Pen Tests
needs:
- deploy-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: ZAP Scan
uses: zaproxy/action-full-scan@v0.3.0
with:
target: https://${{ env.NAME }}-test-backend.apps.silver.devops.gov.bc.ca/
cmd_options: "-a"
allow_issue_writing: false
fail_action: false
zap-frontend:
name: Frontend Pen Tests
needs:
- deploy-test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: ZAP Scan
uses: zaproxy/action-full-scan@v0.4.0
with:
target: https://${{ env.NAME }}-test-frontend.apps.silver.devops.gov.bc.ca/
cmd_options: "-a"
allow_issue_writing: false
fail_action: false
deploy-prod:
name: PROD Deployment
needs:
- zap-backend
- zap-frontend
runs-on: ubuntu-latest
environment:
name: prod
env:
ZONE: prod
PREV: test
steps:
- uses: actions/checkout@v2
- name: Deploy
run: |
# Login to OpenShift and select project
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }}
oc project ${{ secrets.OC_NAMESPACE }}
# Clear stale images for import/replacement
if [ $(oc get is -l app=${{ env.NAME }}-${{ env.ZONE }} -o name | grep -v database | wc -l) -gt 0 ]; then
oc delete is -l app=${{ env.NAME }}-${{ env.ZONE }}
fi
# Process and apply deployment templates
oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc apply -f -
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p PROMOTE=${{ github.repository }}:${{ env.PREV }}-backend | oc apply -f -
oc process -f .github/openshift/deploy.frontend.yml -p ZONE=${{ env.ZONE }} \
-p PROMOTE=${{ github.repository }}:${{ env.PREV }}-frontend | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-backend -w
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-frontend -w
# Remove completed build runs, build pods and deployment pods
for p in $(oc get po | grep "Completed" | awk '{print $1}')
do
oc delete po ${p}
done
- name: Promote Backend Image to PROD
uses: shrink/actions-docker-registry-tag@v2
with:
registry: ghcr.io
repository: ${{ github.repository }}
target: ${{ env.PREV }}-backend
tags: |
prod-backend
- name: Promote Frontend Image to PROD
uses: shrink/actions-docker-registry-tag@v2
with:
registry: ghcr.io
repository: ${{ github.repository }}
target: ${{ env.PREV }}-frontend
tags: |
prod-frontend