-
Notifications
You must be signed in to change notification settings - Fork 0
367 lines (315 loc) · 11.1 KB
/
app-pipeline.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
name: python-application-deployment
env:
AZURE_WEBAPP_NAME: python-postgres-azure
PYTHON_VERSION: "3.13"
on:
push:
branches: ["main"]
paths:
- "**"
- "!infrastructure/bootstrap/**"
- "!db/**"
- "!.github/workflows/infra-pipeline.yml"
- "!.github/workflows/app-pipeline-pr.yml"
workflow_dispatch:
permissions:
contents: write
id-token: write # This is required for requesting the JWT
jobs:
conventional-commit-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Conventional commit check
uses: cocogitto/cocogitto-action@v3
linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python version
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install dependencies
run: pip install black flake8
- name: Check Formatting and linting
run: black ./ --check && flake8
static-code-analysis:
runs-on: ubuntu-latest
needs:
- linting
- conventional-commit-check
steps:
- uses: actions/checkout@v4
- name: Set up Python version
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install dependencies
run: pip install bandit
- name: SAST
run: bandit -r ./rates -c .bandit.yaml
dependency-vulnerability-analysis:
runs-on: ubuntu-latest
defaults:
run:
working-directory: rates
needs:
- linting
- conventional-commit-check
steps:
- uses: actions/checkout@v4
- name: Set up Python version
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install dependencies
run: pip install safety
- name: Safety Check
run: safety check --file requirements.txt.lock --full-report
placeholder-unit-test:
runs-on: ubuntu-latest
needs:
- linting
- conventional-commit-check
steps:
- name: Placeholder for unit test
run: |
echo "Implement Unit test and execute them here in the pipeline"
bdd-test:
runs-on: ubuntu-latest
needs:
- linting
- conventional-commit-check
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/checkout@v4
- name: Set up Python version
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Run Behave BDD Tests
run: |
make start-app-db
pip install behave requests
echo "****** Running behave tests ******"
behave
make stop-app-db
docker-lint-build-scan-push:
runs-on: ubuntu-latest
needs:
- static-code-analysis
- dependency-vulnerability-analysis
- placeholder-unit-test
- bdd-test
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: fetch-tags
run: git fetch --tags origin
shell: bash
- name: Set up Python version
uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: "pip"
- name: Install Dependencies
run: |
echo " ** Install Checkov **"
pip install checkov
echo "** Install Trivy **"
sudo apt-get install wget apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install trivy
- name: Dockerfile vulnerability Analysis
run: |
checkov -d . --framework dockerfile --skip-check CKV_DOCKER_2
- id: bump-version
name: Bump to Next Semver Version
uses: armakuni/github-actions/[email protected]
- name: Build Docker Image
run: |
echo "The next tag version is ::: ${{ steps.bump-version.outputs.current-version }}"
echo "${{ steps.bump-version.outputs.current-version }}" > tag-version.txt
docker build -t "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current-version }}" .
echo "docker image built successfully"
- name: Scan Docker Image Vulnerabilities
run: |
trivy image "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current-version }}"
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push Docker Image
run: |
docker tag "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current-version }}" "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest"
docker push "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:${{ steps.bump-version.outputs.current-version }}"
docker push "${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:latest"
- name: Upload Next Tag Version
uses: actions/upload-artifact@v4
with:
name: tag-version
path: tag-version.txt
dev-deploy-to-az-container-apps:
runs-on: ubuntu-latest
needs:
- docker-lint-build-scan-push
defaults:
run:
working-directory: infrastructure/app-infra
environment:
name: approve-dev-deployment
steps:
- uses: actions/checkout@v4
- name: Log in to Azure using OIDC
uses: azure/login@v2
with:
client-id: ${{ secrets.AZ_CLIENT_ID }}
tenant-id: ${{ secrets.AZ_TENANT_ID }}
subscription-id: ${{ secrets.AZ_SUBSCRIPTION_ID }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.5.7
- name: Terraform Init
id: init
run: terraform init -backend-config=./dev/backend-config.hcl
env:
ARM_CLIENT_ID: ${{ secrets.AZ_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZ_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZ_TENANT_ID }}
ARM_USE_OIDC: true
- name: Download Next Tag Version
uses: actions/download-artifact@v4
with:
name: tag-version
- name: Terraform Apply
run: |
TAG_VERSION=$(cat ../../tag-version.txt)
terraform apply --auto-approve -var-file=./dev/terraform.tfvars -var="registry_username=${{ secrets.DOCKERHUB_USERNAME }}" -var="registry_password=${{ secrets.DOCKERHUB_TOKEN }}" -var="image=${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}:$TAG_VERSION"
env:
ARM_CLIENT_ID: ${{ secrets.AZ_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZ_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZ_TENANT_ID }}
ARM_USE_OIDC: true
placeholder-dev-e2e-test:
runs-on: ubuntu-latest
needs:
- dev-deploy-to-az-container-apps
steps:
- name: Placeholder for e2e test
run: |
echo "Implement e2e test and execute them here in the pipeline"
placeholder-pre-deploy-to-az-container-apps:
runs-on: ubuntu-latest
needs:
- placeholder-dev-e2e-test
steps:
- name: Download Next Tag Version
uses: actions/download-artifact@v4
with:
name: tag-version
- name: Placeholder pre-deploy-to-az-container-apps
run: |
cat tag-version.txt
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
placeholder-pre-e2e-test:
runs-on: ubuntu-latest
needs:
- placeholder-pre-deploy-to-az-container-apps
steps:
- name: Placeholder pre-deploy-to-az-container-apps
run: |
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
placeholder-pre-pen-test:
runs-on: ubuntu-latest
needs:
- placeholder-pre-deploy-to-az-container-apps
steps:
- name: Placeholder for pen test
run: |
echo "Implement pen test and execute them here in the pipeline"
placeholder-pre-load-performance-test:
runs-on: ubuntu-latest
needs:
- placeholder-pre-deploy-to-az-container-apps
steps:
- name: Placeholder pre-deploy-to-az-container-apps
run: |
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
placeholder-change-management-entry:
runs-on: ubuntu-latest
needs:
- placeholder-pre-load-performance-test
- placeholder-pre-pen-test
- placeholder-pre-e2e-test
steps:
- name: Placeholder pre-deploy-to-az-container-apps
run: |
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
placeholder-prod-manual-approval:
runs-on: ubuntu-latest
needs:
- placeholder-change-management-entry
steps:
- name: Download Next Tag Version
uses: actions/download-artifact@v4
with:
name: tag-version
- name: Placeholder pre-deploy-to-az-container-apps
run: |
cat tag-version.txt
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
placeholder-prod-deploy-to-az-container-apps:
runs-on: ubuntu-latest
needs:
- placeholder-prod-manual-approval
steps:
- name: Placeholder pre-deploy-to-az-container-apps
run: |
echo "Implement pre-deploy-to-az-container-apps and execute them here in the pipeline"
placeholder-prod-e2e-test:
runs-on: ubuntu-latest
needs:
- placeholder-prod-deploy-to-az-container-apps
steps:
- name: Download Next Tag Version
uses: actions/download-artifact@v4
with:
name: tag-version
- name: Placeholder prod-deploy-to-az-container-apps
run: |
cat tag-version.txt
echo "Implement prod-deploy-to-az-container-apps and execute them here in the pipeline"
create-release:
needs:
- placeholder-prod-deploy-to-az-container-apps
if: github.ref == 'refs/heads/main'
uses: armakuni/github-actions/.github/workflows/[email protected]
secrets: inherit
with:
download-artifacts: true
placeholder-prod-pen-test:
runs-on: ubuntu-latest
needs:
- placeholder-prod-deploy-to-az-container-apps
steps:
- name: Placeholder for pen test
run: |
echo "Implement pen test and execute them here in the pipeline"