This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
260 lines (227 loc) · 9.3 KB
/
ch7-qa-sec-poi.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
name: POI CICD - Ch7-BlueGreenDeploymentWithSecurityAndLoadTesting
# Variables used in the jobs
env:
registry: openhackflo1xyl7acr.azurecr.io
repository: devopsoh/api-poi
docker_path: apis/poi/web
webapp_name: openhackflo1xyl7poi
poi_path: apis/poi/**
staging_url: https://openhackflo1xyl7poi-staging.azurewebsites.net
prod_url: https://openhackflo1xyl7poi.azurewebsites.net
resource_group: openhackflo1xyl7rg
build_name: POI
# If you want to trigger this branch then change the branch name to a usable branch name
on:
push:
branches: [ REPLACE-WITH-MASTER-BRANCH-NAME ]
paths:
- apis/poi/**
- .github/workflows/ch7-qa-sec-poi.yml
pull_request:
branches: [ REPLACE-WITH-MASTER-BRANCH-NAME ]
paths:
- apis/poi/**
- .github/workflows/ch7-qa-sec-poi.yml
jobs:
# CI Phase - BUILD AND TEST CODE CHANGES
build_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
# If you want to specify a specific DOTNET version you may uncomment this line. It is not needed.
#with:
# dotnet-version: '3.1.202'
- name: Add Code Coverage Tools
working-directory: apis/poi/tests/UnitTests
run: dotnet add package coverlet.msbuild
- name: Install dependencies
run: dotnet restore apis/poi/web/*.csproj
- name: .NET Build Web
run: dotnet build --configuration Release --no-restore apis/poi/web/*.csproj
- name: .NET Build Unit Tests
run: dotnet build --configuration Release apis/poi/tests/UnitTests/UnitTests.csproj
- name: .NET Test
run: dotnet test --no-restore --verbosity normal apis/poi/tests/UnitTests /p:CollectCoverage=true /p:CoverletOutput=lcov/ /p:CoverletOutputFormat=lcov
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: apis/poi/tests/UnitTests/lcov/coverage.info
base-path: apis/poi
flag-name: Unit
- name: Create Issue
uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 2 - 1 - PUSH TO ACR
docker_build_and_push:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: build_and_test
steps:
- uses: actions/checkout@v2
- name: Docker login
run: docker login $registry -u ${{ secrets.ACR_USER }} -p ${{ secrets.ACR_KEY }}
- name: Docker build
run: docker build -t $registry/$repository:${{github.run_number}} --build-arg build_version=${{github.run_number}} $docker_path
- name: Docker Push
run: docker push $registry/$repository:${{github.run_number}}
- name: Create Issue
uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 2 - 2 - PUSH NEW CODE FROM ACR TO WEBAPP STAGING SLOT
deploy_staging:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: docker_build_and_push
steps:
- name: Azure authentication
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Azure WebApp
uses: Azure/webapps-deploy@v2
with:
app-name: ${{ env.webapp_name }}
slot-name: staging
images: ${{ env.registry }}/${{ env.repository }}:${{github.run_number}}
- name: Create Issue
uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 3 - 1 - VALIDATE WEBAPP STAGING SLOT HTTP STATUS
validate_staging:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: deploy_staging
steps:
- uses: actions/checkout@v2
- name: Run Validation script
run: |
pwd
ls -la
chmod +x poihttp.sh
./poihttp.sh
- name: Create Issue
uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 7 - LOAD TESTING WITH K6
k6_cloud_test:
if: github.ref == 'refs/heads/openhack_refresh'
name: k6 cloud test run
runs-on: ubuntu-latest
needs: validate_staging
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Run k6 cloud test
uses: k6io/action@v0.1
with:
filename: test-poi.js
cloud: true
token: ${{ secrets.K6_CLOUD_API_TOKEN }}
# CD Phase 3 - 2 - SWAP SLOTS FROM STAGING TO PRODUCTION
swap_slots:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: k6_cloud_test
steps:
- name: Azure authentication
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Swap staging to production
run: |
az webapp deployment slot swap --name $webapp_name --resource-group $resource_group --slot staging --target-slot production
- name: Create Issue
uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 3 - 3 - VALIDATE WEBAPP PRODUCTION SLOT HTTP STATUS
validate_production:
if: github.ref == 'refs/heads/openhack_refresh'
runs-on: ubuntu-latest
needs: swap_slots
steps:
- uses: actions/checkout@v2
- name: Run Validation script
run: |
pwd
ls -la
chmod +x prod-poi-http.sh
./prod-poi-http.sh
- name: Create Issue
uses: actions/github-script@0.9.0
if: failure()
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
let body = "${{ env.build_name }} Worflow Failure \n Build Number: ${{ github.run_number }} \n Build Log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} \n SHA: [${{ github.sha }}](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) \n";
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "${{ env.build_name }} Workflow ${{ github.run_number }} Failed! ",
body: body
});
# CD Phase 4 - 1 - ROLLBACK IN CASE THE PRODUCTION SLOT FAILS VALIDATION
roll_back:
if: failure()
runs-on: ubuntu-latest
needs: validate_production
steps:
- name: Azure authentication
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Swap production and staging
run: |
az webapp deployment slot swap --name $webapp_name --resource-group $resource_group --slot staging --target-slot production