-
Notifications
You must be signed in to change notification settings - Fork 3
303 lines (280 loc) · 11.1 KB
/
deploy-branch.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
name: Deploy branch
run-name: Deploy demo [${{ github.head_ref || github.ref_name }}]
on:
pull_request:
branches:
- main
types:
- opened
- reopened
- ready_for_review
- synchronize
concurrency: deploy-demo-${{ github.head_ref || github.ref_name }}
permissions:
id-token: write
contents: read
jobs:
get-head-commit:
name: Get head commit
runs-on: ubuntu-latest
outputs:
commit-message: ${{ steps.get-head-commit.outputs.commit-message }}
steps:
- name: Checkout Commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get Head Commit Message
id: get-head-commit
run: echo "commit-message=$(git show -s --format=%s)" >> "$GITHUB_OUTPUT"
- name: Show commit message
run: echo "Git commit message \`$(git show -s --format=%s)\`" >> $GITHUB_STEP_SUMMARY
push-frontend-image:
if: contains(needs.get-head-commit.outputs.commit-message, '[deploy]') == true
name: Push frontend image
needs: get-head-commit
runs-on: ubuntu-latest
environment:
name: demo
url: ${{ steps.push-image.outputs.image-url }}
outputs:
image-uri: ${{ steps.push-image.outputs.image-uri }}
steps:
- name: Login to GDS Dev Dynatrace Container Registry
uses: docker/login-action@v3
with:
registry: khw46367.live.dynatrace.com
username: khw46367
password: ${{ secrets.DYNATRACE_PAAS_TOKEN }}
- name: Push Docker image
uses: govuk-one-login/github-actions/aws/ecr/build-docker-image@7d56b09b4d2a9a9c6005843d28f31a2333ad1373 # 13/03/2024
id: push-image
with:
image-version: ${{ github.sha }}
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }}
repository: ${{ vars.FRONTEND_CONTAINER_REPOSITORY_NAME }}
image-tags: "${{ github.head_ref || github.ref_name }}"
dockerfile: infrastructure/frontend/Dockerfile
deploy-frontend:
if: contains(needs.get-head-commit.outputs.commit-message, '[deploy]') == true
name: Deploy frontend (demo)
needs: [ get-head-commit, push-frontend-image, deploy-dynamodb, deploy-cognito, deploy-api ]
runs-on: ubuntu-latest
outputs:
stack-name: ${{ steps.deploy.outputs.stack-name }}
stack-url: ${{ steps.deploy.outputs.stack-url }}
deployment-url: ${{ steps.get-deployment-url.outputs.url }}
environment:
name: demo
url: ${{ steps.get-deployment-url.outputs.url || steps.deploy.outputs.stack-url }}
steps:
- name: Pull repository
id: checkout
uses: actions/checkout@v4
- name: Get deployment name
id: get-deployment-name
uses: govuk-one-login/github-actions/beautify-branch-name@7d56b09b4d2a9a9c6005843d28f31a2333ad1373 # 13/03/2024
with:
length-limit: 22
prefix: preview
verbose: false
- name: Build
id: build
env:
TEMPLATE_FILE: infrastructure/frontend/frontend.template.yml
IMAGE_URI: ${{ needs.push-frontend-image.outputs.image-uri }}
run: |
sam build --cached \
${TEMPLATE_FILE:+--template $TEMPLATE_FILE}
echo "template=.aws-sam/build/template.yaml" >> "$GITHUB_OUTPUT"
if grep -q "CONTAINER-IMAGE-PLACEHOLDER" .aws-sam/build/template.yaml; then
echo "Replacing \"CONTAINER-IMAGE-PLACEHOLDER\" with new ECR image ref"
sed -i "s|CONTAINER-IMAGE-PLACEHOLDER|$IMAGE_URI|" .aws-sam/build/template.yaml
else
echo "WARNING!!! Image placeholder text \"CONTAINER-IMAGE-PLACEHOLDER\" not found - uploading template anyway"
fi
- name: Deploy
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: deploy
with:
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }}
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }}
delete-failed-stack: true
disable-rollback: false
stack-name-prefix: preview-frontend
template: ${{ steps.build.outputs.template }}
s3-prefix: sse-preview
pull-repository: false
tags: |-
sse:component=frontend
sse:stack-type=preview
sse:application=self-service
sse:deployment-source=github-actions
sse:lifecycle=temporary
parameters: |-
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }}
- name: Get deployment URL
id: get-deployment-url
env:
NAME: AdminToolURL
OUTPUTS: ${{ steps.deploy.outputs.stack-outputs }}
run: |
url=$(jq --raw-output ".$NAME" <<< "$OUTPUTS")
printf "🌐 Deployment URL\n%s" "$url" >> "$GITHUB_STEP_SUMMARY"
echo "url=$url" >> "$GITHUB_OUTPUT"
deploy-dynamodb:
if: contains(needs.get-head-commit.outputs.commit-message, '[deploy]') == true
name: Deploy dynamodb (demo)
needs: get-head-commit
runs-on: ubuntu-latest
environment:
name: demo
url: ${{ steps.deploy.outputs.stack-url }}
outputs:
stack-name: ${{ steps.deploy.outputs.stack-name }}
stack-url: ${{ steps.deploy.outputs.stack-url }}
cache-key: ${{ steps.build.outputs.cache-key }}
steps:
- name: Get deployment name
uses: govuk-one-login/github-actions/beautify-branch-name@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: get-deployment-name
with:
length-limit: 22
prefix: preview
verbose: false
- name: Build
id: build
uses: govuk-one-login/github-actions/sam/build-application@6144f39407b01c9b25b39537b3956deca9e32620 # 22/02/2024
with:
template: backend/dynamodb/dynamodb.template.yml
base-dir: backend/dynamodb
source-dir: backend/dynamodb
cache-name: backend-dynamodb-infra
artifact-name: backend-dynamodb-infrastructure
pull-repository: true
- name: Deploy
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: deploy
with:
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }}
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }}
delete-failed-stack: true
disable-rollback: false
stack-name-prefix: preview-dynamodb
template: .aws-sam/build/template.yaml
cache-name: ${{ steps.build.outputs.cache-key }}
s3-prefix: sse-preview
pull-repository: false
tags: |-
sse:component=dynamodb
sse:stack-type=preview
sse:stack-name=preview-dynamodb
sse:application=self-service
sse:deployment-source=github-actions
parameters: |-
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }}
deploy-cognito:
if: contains(needs.get-head-commit.outputs.commit-message, '[deploy]') == true
name: Deploy cognito (demo)
needs: get-head-commit
runs-on: ubuntu-latest
environment:
name: demo
url: ${{ steps.deploy.outputs.stack-url }}
outputs:
stack-name: ${{ steps.deploy.outputs.stack-name }}
stack-url: ${{ steps.deploy.outputs.stack-url }}
cache-key: ${{ steps.build.outputs.cache-key }}
steps:
- name: Get deployment name
uses: govuk-one-login/github-actions/beautify-branch-name@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: get-deployment-name
with:
length-limit: 22
prefix: preview
verbose: false
- name: Build
id: build
uses: govuk-one-login/github-actions/sam/build-application@6144f39407b01c9b25b39537b3956deca9e32620 # 22/02/2024
with:
template: backend/cognito/cognito.template.yml
manifest: backend/cognito/package.json
base-dir: backend/cognito
source-dir: backend/cognito
cache-name: backend-cognito-infra
artifact-name: backend-cognito-infrastructure
pull-repository: true
- name: Deploy stack
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: deploy
with:
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }}
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }}
delete-failed-stack: true
disable-rollback: false
stack-name-prefix: preview-cognito
template: .aws-sam/build/template.yaml
cache-name: ${{ steps.build.outputs.cache-key }}
s3-prefix: sse-preview
pull-repository: false
tags: |-
sse:component=cognito
sse:stack-type=preview
sse:stack-name=preview-cognito
sse:application=self-service
sse:deployment-source=github-actions
parameters: |-
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }}
deploy-api:
if: contains(needs.get-head-commit.outputs.commit-message, '[deploy]') == true
name: Deploy API (demo)
needs: get-head-commit
runs-on: ubuntu-latest
environment:
name: demo
url: ${{ steps.deploy.outputs.stack-url }}
outputs:
stack-name: ${{ steps.deploy.outputs.stack-name }}
stack-url: ${{ steps.deploy.outputs.stack-url }}
cache-key: ${{ steps.build.outputs.cache-key }}
steps:
- name: Get deployment name
uses: govuk-one-login/github-actions/beautify-branch-name@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: get-deployment-name
with:
length-limit: 22
prefix: preview
verbose: false
- name: Build
id: build
uses: govuk-one-login/github-actions/sam/build-application@6144f39407b01c9b25b39537b3956deca9e32620 # 22/02/2024
with:
template: backend/api/api.template.yml
manifest: backend/api/package.json
base-dir: backend/api
source-dir: backend/api
additional-artifact-paths: backend/api/state-machines
cache-name: backend-api-infra
artifact-name: backend-api-infrastructure
pull-repository: true
- name: Deploy stack
uses: govuk-one-login/github-actions/sam/deploy-stack@db4b3614f5f863f56a5356052262878ecec83b31 # 22/07/2024
id: deploy
with:
aws-role-arn: ${{ vars.DEPLOYMENT_ROLE_ARN }}
sam-deployment-bucket: ${{ vars.DEPLOYMENT_ARTIFACTS_BUCKET }}
delete-failed-stack: true
disable-rollback: false
stack-name-prefix: preview-api
template: .aws-sam/build/template.yaml
cache-name: ${{ steps.build.outputs.cache-key }}
s3-prefix: sse-preview
pull-repository: false
tags: |-
sse:component=api
sse:stack-type=preview
sse:stack-name=preview-api
sse:application=self-service
sse:deployment-source=github-actions
parameters: |-
DeploymentName=${{ steps.get-deployment-name.outputs.pretty-branch-name }}