forked from microsoft/PyRIT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui-deploy.yml
More file actions
229 lines (211 loc) · 8.3 KB
/
Copy pathgui-deploy.yml
File metadata and controls
229 lines (211 loc) · 8.3 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
# CI/CD pipeline for the CoPyRIT GUI.
#
# App-only test deployment is the default. Infrastructure reconciliation is
# explicit and leaves the running app unchanged before deploying new code.
trigger:
branches:
include:
- main
paths:
include:
- pyrit/backend/**
- frontend/**
- docker/**
- infra/**
pr: none
parameters:
- name: deployInfra
displayName: 'Deploy Infrastructure'
type: boolean
default: false
- name: deployToProd
displayName: 'Deploy to production'
type: boolean
default: false
variables:
azureServiceConnection: 'copyrit-gui-azure'
stages:
- stage: ValidateInputs
displayName: 'Validate Inputs'
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: ValidateProdSource
displayName: 'Validate production source'
steps:
- checkout: none
- bash: |
set -euo pipefail
if [[ '${{ parameters.deployToProd }}' == 'true' \
&& "$BUILD_SOURCEBRANCH" != refs/heads/main ]]; then
echo "##vso[task.logissue type=error]Production deployment requires a commit merged to refs/heads/main"
exit 1
fi
displayName: 'Validate production source'
- stage: Build
displayName: 'Build and Push Image'
dependsOn: ValidateInputs
variables:
- group: copyrit-gui-common
pool:
vmImage: 'ubuntu-latest'
jobs:
- job: BuildAndPush
displayName: 'Build and push immutable source image'
steps:
- checkout: self
fetchDepth: 1
- task: AzureCLI@2
name: BuildImage
displayName: 'Build and push Docker image'
env:
PYRIT_ACR_NAME: $(acrName)
PYRIT_ACR_LOGIN_SERVER: $(acrLoginServer)
PYRIT_IMAGE_NAME: $(imageName)
PYRIT_SOURCE_VERSION: $(Build.SourceVersion)
inputs:
azureSubscription: '$(azureServiceConnection)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
set -euo pipefail
required_variables=(
PYRIT_ACR_NAME
PYRIT_ACR_LOGIN_SERVER
PYRIT_IMAGE_NAME
PYRIT_SOURCE_VERSION
)
for variable_name in "${required_variables[@]}"; do
if [[ -z "${!variable_name:-}" || "${!variable_name}" == '$('* ]]; then
echo "##vso[task.logissue type=error]Required build value is missing: $variable_name"
exit 1
fi
done
repository_pattern='^[a-z0-9]+([._-][a-z0-9]+)*(/[a-z0-9]+([._-][a-z0-9]+)*)*$'
if [[ ! "$PYRIT_ACR_NAME" =~ ^[a-z0-9]{5,50}$ \
|| "$PYRIT_ACR_LOGIN_SERVER" != "$PYRIT_ACR_NAME.azurecr.io" \
|| ! "$PYRIT_IMAGE_NAME" =~ $repository_pattern \
|| ! "$PYRIT_SOURCE_VERSION" =~ ^[0-9a-fA-F]{40}$ ]]; then
echo "##vso[task.logissue type=error]Invalid registry, repository, or source version"
exit 1
fi
docker build \
-f .devcontainer/Dockerfile \
-t pyrit-devcontainer \
.devcontainer/
image="$PYRIT_ACR_LOGIN_SERVER/$PYRIT_IMAGE_NAME:$PYRIT_SOURCE_VERSION"
docker build --no-cache \
-f docker/Dockerfile \
-t "$image" \
--build-arg BASE_IMAGE=pyrit-devcontainer \
--build-arg PYRIT_SOURCE=local \
--build-arg GIT_COMMIT="$PYRIT_SOURCE_VERSION" \
--build-arg GIT_MODIFIED=false \
.
az acr login --name "$PYRIT_ACR_NAME"
push_output=$(docker push "$image")
printf '%s\n' "$push_output"
digest=$(sed -nE 's/.*digest: (sha256:[0-9a-fA-F]{64}).*/\1/p' <<< "$push_output" | tail -n 1)
if [[ ! "$digest" =~ ^sha256:[0-9a-fA-F]{64}$ ]]; then
echo "##vso[task.logissue type=error]Docker push did not return an immutable digest"
exit 1
fi
immutable_image="$PYRIT_ACR_LOGIN_SERVER/$PYRIT_IMAGE_NAME@$digest"
echo "##vso[task.setvariable variable=immutableImage;isOutput=true]$immutable_image"
- template: infra/pipelines/deploy-stage.yml
parameters:
stageName: DeployTestInfra
displayName: 'Deploy test infrastructure'
deploymentName: DeployInfrastructure
dependsOn:
- Build
slot: test
phase: infra
condition: and(succeeded(), eq('${{ parameters.deployInfra }}', 'true'))
- template: infra/pipelines/deploy-stage.yml
parameters:
stageName: DeployTest
displayName: 'Deploy app to Test'
deploymentName: DeployToTest
dependsOn:
- Build
- DeployTestInfra
slot: test
phase: app
condition: >-
and(not(canceled()),
in(dependencies.Build.result, 'Succeeded', 'SucceededWithIssues'),
or(in(dependencies.DeployTestInfra.result, 'Succeeded', 'SucceededWithIssues'),
and(eq('${{ parameters.deployInfra }}', 'false'),
eq(dependencies.DeployTestInfra.result, 'Skipped'))))
- stage: ApproveProd
displayName: 'Approve Production Deployment'
dependsOn: DeployTest
condition: and(succeeded('DeployTest'), eq('${{ parameters.deployToProd }}', 'true'), eq(variables['Build.SourceBranch'], 'refs/heads/main'))
variables:
- group: copyrit-gui-prod
jobs:
- job: ValidateProdConfiguration
displayName: 'Validate production authorization configuration'
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: none
- bash: |
set -euo pipefail
if [[ -z "${PROD_APPROVERS:-}" || "$PROD_APPROVERS" == '$('* ]]; then
echo "##vso[task.logissue type=error]copyrit-gui-prod must define prodApprovers before production deployment"
exit 1
fi
displayName: 'Validate production approvers'
env:
PROD_APPROVERS: $(prodApprovers)
- job: WaitForProdApproval
displayName: 'Validate production readiness'
dependsOn: ValidateProdConfiguration
pool: server
timeoutInMinutes: 1440
steps:
- task: ManualValidation@1
timeoutInMinutes: 1440
inputs:
notifyUsers: '$(prodApprovers)'
approvers: '$(prodApprovers)'
allowApproversToApproveTheirOwnRuns: false
instructions: |
Confirm test is healthy, Entra and backend group authorization work,
and the static test egress IP is allow-listed.
Infrastructure deployment requested: ${{ parameters.deployInfra }}.
App deployment reconciles application configuration and preserves
the existing public/private access mode.
If infrastructure is requested, approve the production Private Link
cutover and configuration changes before the new code is deployed.
onTimeout: reject
- template: infra/pipelines/deploy-stage.yml
parameters:
stageName: DeployProdInfra
displayName: 'Deploy prod infrastructure'
deploymentName: DeployInfrastructure
dependsOn:
- ApproveProd
slot: prod
phase: infra
condition: and(succeeded(), eq('${{ parameters.deployInfra }}', 'true'))
- template: infra/pipelines/deploy-stage.yml
parameters:
stageName: DeployProd
displayName: 'Deploy app to Production'
deploymentName: DeployToProd
dependsOn:
- ApproveProd
- Build
- DeployProdInfra
slot: prod
phase: app
condition: >-
and(not(canceled()),
in(dependencies.Build.result, 'Succeeded', 'SucceededWithIssues'),
in(dependencies.ApproveProd.result, 'Succeeded', 'SucceededWithIssues'),
or(in(dependencies.DeployProdInfra.result, 'Succeeded', 'SucceededWithIssues'),
and(eq('${{ parameters.deployInfra }}', 'false'),
eq(dependencies.DeployProdInfra.result, 'Skipped'))))