This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
generated from communitiesuk/funding-service-design-TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 1
396 lines (348 loc) · 14.3 KB
/
copilot_deploy.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
name: Deploy to AWS
on:
workflow_dispatch:
inputs:
environment:
description: Which AWS Account to use
type: choice
required: true
options:
- dev
- test
- uat
- production
run_performance_tests:
required: false
default: false
type: boolean
description: Run performance tests
run_e2e_tests:
required: false
default: false
type: boolean
description: Run e2e tests
push:
paths:
- '!**/README.md'
- 'app/**'
- 'tests/**'
- 'requirements-dev.in'
- 'requirements-dev.txt'
- 'requirements.in'
- 'requirements.txt'
- '.github/workflows/copilot_deploy.yml'
jobs:
tag_version:
runs-on: ubuntu-latest
outputs:
version_to_tag: ${{ steps.assessment_tagging.outputs.tag_value }}
steps:
- id: assessment_tagging
run: |
echo "tag_value=$(echo '${{ github.ref }}' | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_OUTPUT
pre_deploy_tests:
uses: communitiesuk/funding-service-design-workflows/.github/workflows/pre-deploy.yml@main
with:
assets_required: true
postgres_unit_testing: false
paketo_build:
needs: [ tag_version ]
concurrency: build-assessment-pack
permissions:
packages: write
uses: communitiesuk/funding-service-design-workflows/.github/workflows/package.yml@main
with:
version_to_build: ${{ needs.tag_version.outputs.version_to_tag }}
owner: ${{ github.repository_owner }}
application: funding-service-design-assessment
assets_required: true
copilot_environments_workflow_setup:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.copilot_env_matrix.outputs.env_list }}
pre_matrix: ${{ steps.copilot_env_matrix.outputs.pre_deploy_list }}
post_matrix: ${{ steps.copilot_env_matrix.outputs.post_deploy_list }}
steps:
- id: copilot_env_matrix
run: |
if [ "${{ inputs.environment }}" != "" ]; then
echo "env_list=[\"${{ inputs.environment }}\"]" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" == 'refs/heads/main' ]; then
echo "pre_deploy_list=[\"dev\", \"test\"]" >> $GITHUB_OUTPUT
echo "post_deploy_list=[\"uat\", \"production\"]" >> $GITHUB_OUTPUT
else
echo "pre_deploy_list=[\"dev\", \"test\"]" >> $GITHUB_OUTPUT
fi
individual_deploy:
if: inputs.environment != ''
concurrency:
group: 'fsd-preaward-copilot-individual-${{ matrix.value }}'
cancel-in-progress: false
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
needs: [ tag_version, pre_deploy_tests, paketo_build, copilot_environments_workflow_setup ]
runs-on: ubuntu-latest
continue-on-error: true
strategy:
max-parallel: 1
matrix:
value: ${{ fromJSON(needs.copilot_environments_workflow_setup.outputs.matrix) }}
fail-fast: false
environment: ${{ matrix.value }}
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Get current date
shell: bash
id: currentdatetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
role-session-name: ASSESSMENT_${{ matrix.value }}_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
aws-region: eu-west-2
- name: Install AWS Copilot CLI
shell: bash
run: |
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
- name: confirm copilot env
shell: bash
run: |
if [ $(copilot env ls) != "${{ matrix.value }}" ]; then
echo $(copilot env ls)
exit 1
fi
- name: Inject Git SHA into manifest
run: |
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-assessment/manifest.yml
- name: Inject replacement image into manifest
run: |
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-assessment:${{ github.ref_name == 'main' && 'latest' || needs.tag_version.outputs.version_to_tag }}"' copilot/fsd-assessment/manifest.yml
- name: Copilot ${{ matrix.value }} deploy
id: deploy_build
run: |
copilot svc deploy --env ${{ matrix.value }} --app pre-award
dev_deploy:
if: ${{ needs.copilot_environments_workflow_setup.outputs.pre_matrix != '' && toJson(fromJson(needs.copilot_environments_workflow_setup.outputs.pre_matrix)) != '[]' }}
concurrency:
group: 'fsd-preaward-copilot-dev'
cancel-in-progress: false
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
needs: [ tag_version, pre_deploy_tests, paketo_build, copilot_environments_workflow_setup ]
runs-on: ubuntu-latest
environment: dev
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Get current date
shell: bash
id: currentdatetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
role-session-name: ASSESSMENT_DEV_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
aws-region: eu-west-2
- name: Install AWS Copilot CLI
shell: bash
run: |
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
- name: confirm copilot env
shell: bash
run: |
if [ $(copilot env ls) != "dev" ]; then
echo $(copilot env ls)
exit 1
fi
- name: Inject Git SHA into manifest
run: |
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-assessment/manifest.yml
- name: Inject replacement image into manifest
run: |
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-assessment:${{ github.ref_name == 'main' && 'latest' || needs.tag_version.outputs.version_to_tag }}"' copilot/fsd-assessment/manifest.yml
- name: Copilot dev deploy
id: deploy_build
run: |
copilot svc deploy --env dev --app pre-award
post_dev_deploy_tests:
needs: dev_deploy
concurrency:
group: 'fsd-preaward-test-dev'
cancel-in-progress: false
secrets:
FSD_GH_APP_ID: ${{ secrets.FSD_GH_APP_ID }}
FSD_GH_APP_KEY: ${{ secrets.FSD_GH_APP_KEY }}
uses: communitiesuk/funding-service-design-workflows/.github/workflows/post-deploy.yml@main
with:
run_performance_tests: ${{ inputs.run_performance_tests || true }}
run_e2e_tests: ${{ inputs.run_e2e_tests || false }}
app_name: assessment
environment: dev
test_deploy:
if: ${{ needs.copilot_environments_workflow_setup.outputs.pre_matrix != '' && toJson(fromJson(needs.copilot_environments_workflow_setup.outputs.pre_matrix)) != '[]' }}
concurrency:
group: 'fsd-preaward-copilot-test'
cancel-in-progress: false
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
needs: [ tag_version, post_dev_deploy_tests, paketo_build, copilot_environments_workflow_setup ]
runs-on: ubuntu-latest
environment: test
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Get current date
shell: bash
id: currentdatetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
role-session-name: ASSESSMENT_TEST_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
aws-region: eu-west-2
- name: Install AWS Copilot CLI
shell: bash
run: |
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
- name: confirm copilot env
shell: bash
run: |
if [ $(copilot env ls) != "test" ]; then
echo $(copilot env ls)
exit 1
fi
- name: Inject Git SHA into manifest
run: |
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-assessment/manifest.yml
- name: Inject replacement image into manifest
run: |
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-assessment:${{ github.ref_name == 'main' && 'latest' || needs.tag_version.outputs.version_to_tag }}"' copilot/fsd-assessment/manifest.yml
- name: Copilot test deploy
id: deploy_build
run: |
copilot svc deploy --env test --app pre-award
post_test_deploy_tests:
needs: test_deploy
concurrency:
group: 'fsd-preaward-test-test'
cancel-in-progress: false
secrets:
FSD_GH_APP_ID: ${{ secrets.FSD_GH_APP_ID }}
FSD_GH_APP_KEY: ${{ secrets.FSD_GH_APP_KEY }}
uses: communitiesuk/funding-service-design-workflows/.github/workflows/post-deploy.yml@main
with:
run_performance_tests: ${{ inputs.run_performance_tests || false }}
run_e2e_tests: ${{ inputs.run_e2e_tests || true }}
app_name: assessment
environment: test
uat_deploy:
if: ${{ needs.copilot_environments_workflow_setup.outputs.post_matrix != '' && toJson(fromJson(needs.copilot_environments_workflow_setup.outputs.post_matrix)) != '[]' }}
concurrency:
group: 'fsd-preaward-copilot-uat'
cancel-in-progress: false
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
needs: [ tag_version, post_test_deploy_tests, paketo_build, copilot_environments_workflow_setup ]
runs-on: ubuntu-latest
environment: uat
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Get current date
shell: bash
id: currentdatetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
role-session-name: ASSESSMENT_UAT_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
aws-region: eu-west-2
- name: Install AWS Copilot CLI
shell: bash
run: |
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
- name: confirm copilot env
shell: bash
run: |
if [ $(copilot env ls) != "uat" ]; then
echo $(copilot env ls)
exit 1
fi
- name: Inject Git SHA into manifest
run: |
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-assessment/manifest.yml
- name: Inject replacement image into manifest
run: |
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-assessment:${{ github.ref_name == 'main' && 'latest' || needs.tag_version.outputs.version_to_tag }}"' copilot/fsd-assessment/manifest.yml
- name: Copilot uat deploy
id: deploy_build
run: |
copilot svc deploy --env uat --app pre-award
post_uat_deploy_tests:
needs: uat_deploy
concurrency:
group: 'fsd-preaward-test-uat'
cancel-in-progress: false
secrets:
FSD_GH_APP_ID: ${{ secrets.FSD_GH_APP_ID }}
FSD_GH_APP_KEY: ${{ secrets.FSD_GH_APP_KEY }}
uses: communitiesuk/funding-service-design-workflows/.github/workflows/post-deploy.yml@main
with:
run_performance_tests: ${{ inputs.run_performance_tests || false }}
run_e2e_tests: ${{ inputs.run_e2e_tests || true }}
app_name: assessment
environment: uat
production_deploy:
if: ${{ needs.copilot_environments_workflow_setup.outputs.post_matrix != '' && toJson(fromJson(needs.copilot_environments_workflow_setup.outputs.post_matrix)) != '[]' }}
concurrency:
group: 'fsd-preaward-copilot-production'
cancel-in-progress: false
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
needs: [ tag_version, post_uat_deploy_tests, paketo_build, copilot_environments_workflow_setup ]
runs-on: ubuntu-latest
environment: production
steps:
- name: Git clone the repository
uses: actions/checkout@v4
- name: Get current date
shell: bash
id: currentdatetime
run: echo "datetime=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT }}:role/GithubCopilotDeploy
role-session-name: ASSESSMENT_PRODUCTION_COPILOT_${{ steps.currentdatetime.outputs.datetime }}
aws-region: eu-west-2
- name: Install AWS Copilot CLI
shell: bash
run: |
curl -Lo aws-copilot https://github.com/aws/copilot-cli/releases/latest/download/copilot-linux && chmod +x aws-copilot && sudo mv aws-copilot /usr/local/bin/copilot
- name: confirm copilot env
shell: bash
run: |
if [ $(copilot env ls) != "production" ]; then
echo $(copilot env ls)
exit 1
fi
- name: Inject Git SHA into manifest
run: |
yq -i '.variables.GITHUB_SHA = "${{ github.sha }}"' copilot/fsd-assessment/manifest.yml
- name: Inject replacement image into manifest
run: |
yq -i '.image.location = "ghcr.io/communitiesuk/funding-service-design-assessment:${{ github.ref_name == 'main' && 'latest' || needs.tag_version.outputs.version_to_tag }}"' copilot/fsd-assessment/manifest.yml
- name: Copilot production deploy
id: deploy_build
run: |
copilot svc deploy --env production --app pre-award