-
Notifications
You must be signed in to change notification settings - Fork 4
237 lines (218 loc) · 7.94 KB
/
deploy-backend.yml
File metadata and controls
237 lines (218 loc) · 7.94 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
name: Deploy Backend
on:
workflow_call:
inputs:
apigee_environment:
required: true
type: string
build_recordprocessor_image:
required: false
type: boolean
default: false
recordprocessor_image_version:
required: false
type: string
default: ""
diff_base_sha:
required: false
type: string
default: ""
diff_head_sha:
required: false
type: string
default: ""
run_diff_check:
required: false
type: boolean
default: false
create_mns_subscription:
required: false
type: boolean
default: true
environment:
required: true
type: string
sub_environment:
required: true
type: string
outputs:
recordprocessor_image_version:
description: Selected immutable image selector used for recordprocessor deployment
value: ${{ jobs.deploy-recordprocessor-image.outputs.image_uri }}
workflow_dispatch:
inputs:
apigee_environment:
type: choice
description: Select the Apigee proxy environment
options:
- internal-dev
- internal-qa
- int
- ref
- prod
create_mns_subscription:
description: Create an MNS Subscription programatically. Only available in AWS dev
required: false
type: boolean
default: true
environment:
type: choice
description: Select the AWS backend environment
options:
- dev
- preprod
- prod
build_recordprocessor_image:
description: Build and publish a new recordprocessor image
required: true
type: boolean
default: true
recordprocessor_image_version:
description: Existing immutable recordprocessor image selector (tag, digest, or image URI) for reuse mode
required: false
type: string
default: ""
diff_base_sha:
description: Base commit SHA for diff checks
required: false
type: string
default: ""
diff_head_sha:
description: Head commit SHA for diff checks
required: false
type: string
default: ""
run_diff_check:
description: Enable diff checks to auto-build on code changes
required: true
type: boolean
default: false
sub_environment:
type: string
description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments
env: # Sonarcloud - do not allow direct usage of untrusted data
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
ENVIRONMENT: ${{ inputs.environment }}
SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
run-name: Deploy Backend - ${{ inputs.environment }} ${{ inputs.sub_environment }}
jobs:
deploy-recordprocessor-image:
name: Deploy recordprocessor image
uses: ./.github/workflows/deploy-lambda-artifact.yml
with:
lambda_name: recordprocessor
environment: ${{ inputs.environment }}
sub_environment: ${{ inputs.sub_environment }}
build_image: ${{ inputs.build_recordprocessor_image }}
image_version: ${{ inputs.recordprocessor_image_version }}
run_diff_check: ${{ inputs.run_diff_check }}
diff_base_sha: ${{ inputs.diff_base_sha }}
diff_head_sha: ${{ inputs.diff_head_sha }}
lambda_paths: |
lambdas/recordprocessor/
shared_paths: |
lambdas/shared/src/common/
docker_context_path: lambdas
dockerfile_path: lambdas/recordprocessor/Dockerfile
ecr_repository: imms-recordprocessor-repo
image_tag_prefix: ${{ inputs.sub_environment }}-
allow_implicit_tag_prefix_reuse: ${{ inputs.sub_environment == 'internal-dev' || startsWith(inputs.sub_environment, 'pr-') }}
terraform-plan:
permissions:
id-token: write
contents: read
needs:
- deploy-recordprocessor-image
if: ${{ !cancelled() && needs.deploy-recordprocessor-image.result == 'success' }}
outputs:
recordprocessor_image_uri: ${{ needs.deploy-recordprocessor-image.outputs.image_uri }}
runs-on: ubuntu-latest
env:
TF_VAR_recordprocessor_image_uri: ${{ needs.deploy-recordprocessor-image.outputs.image_uri }}
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
- name: Connect to AWS
uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37
with:
aws-region: eu-west-2
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
role-session-name: github-actions
- uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85
with:
terraform_version: "1.12.2"
- name: Terraform Init
working-directory: infrastructure/instance
run: make init
- name: Terraform Plan
# Ignore cancellations to prevent Terraform from being killed while it holds a state lock
# A stuck process can still be killed with the force-cancel API operation
if: ${{ !failure() }}
working-directory: infrastructure/instance
run: make plan-ci
- name: Save Terraform Plan
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f
with:
name: ${{ env.ENVIRONMENT }}-${{ env.SUB_ENVIRONMENT }}-tfplan
path: infrastructure/instance/tfplan
terraform-apply:
permissions:
id-token: write
contents: read
needs: terraform-plan
if: ${{ !cancelled() && needs.terraform-plan.result == 'success' }}
runs-on: ubuntu-latest
env:
TF_VAR_recordprocessor_image_uri: ${{ needs.terraform-plan.outputs.recordprocessor_image_uri }}
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
- uses: aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37
with:
aws-region: eu-west-2
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
role-session-name: github-actions
- uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85
with:
terraform_version: "1.12.2"
- name: Retrieve Terraform Plan
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c
with:
name: ${{ env.ENVIRONMENT }}-${{ env.SUB_ENVIRONMENT }}-tfplan
path: infrastructure/instance
- name: Terraform Init
working-directory: infrastructure/instance
run: make init
- name: Terraform Apply
# Ignore cancellations to prevent Terraform from being killed while it holds a state lock
# A stuck process can still be killed with the force-cancel API operation
if: ${{ !failure() }}
working-directory: infrastructure/instance
run: |
make apply-ci
echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV
- name: Install poetry
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
run: pip install poetry==2.1.4
- uses: actions/setup-python@v6.2.0
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
with:
python-version: 3.11
cache: "poetry"
cache-dependency-path: |
lambdas/mns_subscription/poetry.lock
lambdas/shared/poetry.lock
- name: Create MNS Subscription
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
working-directory: "./lambdas/mns_subscription"
env:
APIGEE_ENVIRONMENT: int
SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }}
run: |
poetry install --no-root
echo "Subscribing SQS to MNS for notifications..."
make subscribe