-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
241 lines (224 loc) · 8.39 KB
/
azure-pipelines.yml
File metadata and controls
241 lines (224 loc) · 8.39 KB
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
# Azure Pipelines CI/CD for MyPortFolio
# Multi-stage pipeline with Build, Test, and Deploy stages
# Follows 20-year DevOps and Software Engineer best practices
trigger:
branches:
include:
- master
- dev
paths:
include:
- backend/**
- frontend/**
- azure-pipelines.yml
- .azure/pipelines/**
- infra/**
pr:
branches:
include:
- master
- dev
paths:
include:
- backend/**
- frontend/**
variables:
- group: 'Portfolio-Pipeline-Variables'
- name: buildConfiguration
value: 'Release'
- name: vmImage
value: 'ubuntu-latest'
# Gradle Cache Settings
- name: GRADLE_USER_HOME
value: $(Pipeline.Workspace)/.gradle
# Key Vault integration is handled via the Variable Group 'Portfolio-Pipeline-Variables' linked above.
# Secrets are automatically available as environment variables in tasks that request them.
stages:
# Stage 1: Build
# Parallel builds for backend and frontend
- stage: Build
displayName: 'Build Stage'
jobs:
- job: BuildBackend
displayName: 'Build Backend'
pool:
vmImage: $(vmImage)
steps:
# Optimization: Cache Gradle dependencies
- task: Cache@2
displayName: 'Cache Gradle packages'
inputs:
key: 'gradle | "$(Agent.OS)" | backend/build.gradle'
restoreKeys: |
gradle | "$(Agent.OS)"
path: $(GRADLE_USER_HOME)
- template: .azure/pipelines/templates/build-docker-image.yml
parameters:
workingDirectory: 'backend'
dockerfilePath: 'backend/Dockerfile'
imageName: 'portfolio-backend'
containerRegistry: 'ACR_Connection'
tags:
- $(Build.BuildId)
- $(Build.SourceBranchName)
- latest
- job: BuildFrontend
displayName: 'Build Frontend'
pool:
vmImage: $(vmImage)
steps:
# Optimization: Cache NPM dependencies
- task: Cache@2
displayName: 'Cache NPM packages'
inputs:
key: 'npm | "$(Agent.OS)" | frontend/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(HOME)/.npm
- template: .azure/pipelines/templates/build-docker-image.yml
parameters:
workingDirectory: 'frontend'
dockerfilePath: 'frontend/Dockerfile'
imageName: 'portfolio-frontend'
containerRegistry: 'ACR_Connection'
buildArgs:
VITE_API_BASE_URL: '$(VITE_API_BASE_URL)'
VITE_GOOGLE_CLIENT_ID: '$(VITE_GOOGLE_CLIENT_ID)'
VITE_GITHUB_CLIENT_ID: '$(VITE_GITHUB_CLIENT_ID)'
VITE_GA_MEASUREMENT_ID: '$(VITE_GA_MEASUREMENT_ID)'
VITE_USE_BACKEND_API: 'true'
tags:
- $(Build.BuildId)
- $(Build.SourceBranchName)
- latest
# Stage 2: Test
- stage: Test
displayName: 'Test Stage'
dependsOn: Build
jobs:
- job: BackendUnitTests
displayName: 'Backend Unit Tests'
pool:
vmImage: $(vmImage)
steps:
- template: .azure/pipelines/test-cases/backend-unit-tests.yml
parameters:
workingDirectory: 'backend'
- job: BackendIntegrationTests
displayName: 'Backend Integration Tests'
pool:
vmImage: $(vmImage)
steps:
- template: .azure/pipelines/test-cases/backend-integration-tests.yml
parameters:
workingDirectory: 'backend'
- job: FrontendUnitTests
displayName: 'Frontend Unit Tests'
pool:
vmImage: $(vmImage)
steps:
- template: .azure/pipelines/test-cases/frontend-unit-tests.yml
parameters:
workingDirectory: 'frontend'
- job: FrontendIntegrationTests
displayName: 'Frontend Integration Tests'
pool:
vmImage: $(vmImage)
steps:
- template: .azure/pipelines/test-cases/frontend-integration-tests.yml
parameters:
workingDirectory: 'frontend'
- job: SecurityScanning
displayName: 'Security Scanning'
pool:
vmImage: $(vmImage)
steps:
- template: .azure/pipelines/templates/security-scan.yml
parameters:
backendImage: '$(ACR_NAME).azurecr.io/portfolio-backend:$(Build.BuildId)'
frontendImage: '$(ACR_NAME).azurecr.io/portfolio-frontend:$(Build.BuildId)'
containerRegistry: 'ACR_Connection'
- job: E2ETests
displayName: 'End-to-End Tests'
pool:
vmImage: $(vmImage)
# Best Practice: Run E2E tests only on master or when specifically requested
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
steps:
- template: .azure/pipelines/test-cases/e2e-tests.yml
# Stage 3: Deploy
# Best Practice: Sequential deployment for non-prod environments (Dev -> Staging)
- stage: DeployDev
displayName: 'Deploy to Dev'
dependsOn: Test
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev'))
jobs:
- deployment: DeployDev
displayName: 'Deploy to Dev Environment'
environment: 'dev'
pool:
vmImage: $(vmImage)
strategy:
runOnce:
deploy:
steps:
- template: .azure/pipelines/templates/deploy-container-app.yml
parameters:
environment: 'dev'
backendAppName: '$(BACKEND_APP_NAME_DEV)'
frontendAppName: '$(FRONTEND_APP_NAME_DEV)'
containerRegistry: 'ACR_Connection'
backendImage: '$(ACR_NAME).azurecr.io/portfolio-backend:$(Build.BuildId)'
frontendImage: '$(ACR_NAME).azurecr.io/portfolio-frontend:$(Build.BuildId)'
resourceGroup: '$(RESOURCE_GROUP_DEV)'
containerAppEnv: '$(CONTAINER_APP_ENV_DEV)'
- stage: DeployStaging
displayName: 'Deploy to Staging'
# Best Practice: Ensure Staging deploys only after Dev succeeds
dependsOn: DeployDev
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev'))
jobs:
- deployment: DeployStaging
displayName: 'Deploy to Staging Environment'
environment: 'staging'
pool:
vmImage: $(vmImage)
strategy:
runOnce:
deploy:
steps:
- template: .azure/pipelines/templates/deploy-container-app.yml
parameters:
environment: 'staging'
backendAppName: '$(BACKEND_APP_NAME_STAGING)'
frontendAppName: '$(FRONTEND_APP_NAME_STAGING)'
containerRegistry: 'ACR_Connection'
backendImage: '$(ACR_NAME).azurecr.io/portfolio-backend:$(Build.BuildId)'
frontendImage: '$(ACR_NAME).azurecr.io/portfolio-frontend:$(Build.BuildId)'
resourceGroup: '$(RESOURCE_GROUP_STAGING)'
containerAppEnv: '$(CONTAINER_APP_ENV_STAGING)'
- stage: DeployProduction
displayName: 'Deploy to Production'
dependsOn: Test
# Best Practice: Production deployment only from master branch
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
jobs:
- deployment: DeployProduction
displayName: 'Deploy to Production Environment'
environment: 'production'
pool:
vmImage: $(vmImage)
strategy:
runOnce:
deploy:
steps:
- template: .azure/pipelines/templates/deploy-container-app.yml
parameters:
environment: 'production'
backendAppName: '$(BACKEND_APP_NAME_PROD)'
frontendAppName: '$(FRONTEND_APP_NAME_PROD)'
containerRegistry: 'ACR_Connection'
backendImage: '$(ACR_NAME).azurecr.io/portfolio-backend:$(Build.BuildId)'
frontendImage: '$(ACR_NAME).azurecr.io/portfolio-frontend:$(Build.BuildId)'
resourceGroup: '$(RESOURCE_GROUP_PROD)'
containerAppEnv: '$(CONTAINER_APP_ENV_PROD)'