Skip to content

Commit a7fd930

Browse files
authored
Merge pull request #6242 from NHSDigital/next
Version 7.2.0
2 parents ba3dd8c + 09438e0 commit a7fd930

175 files changed

Lines changed: 6245 additions & 2551 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-and-push-image.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Build and push images
2-
run-name: Build and push images for ${{ inputs.git-sha || github.sha }}
2+
run-name: Build and push images for ${{ inputs.git_sha || github.sha }}
33

44
on:
55
workflow_dispatch:
@@ -44,11 +44,11 @@ jobs:
4444
- name: Check if dev image exists
4545
id: check-dev-image
4646
run: |
47-
if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids imageTag=$git_ref > /dev/null 2>&1; then
47+
if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids "imageTag=$git_ref" > /dev/null 2>&1; then
4848
echo "Dev image with given tag already exists"
4949
else
5050
echo "Dev image does not exist. Build needed"
51-
echo "${{ matrix.image_type }}-build-needed=true" >> $GITHUB_OUTPUT
51+
echo "${{ matrix.image_type }}-build-needed=true" >> "$GITHUB_OUTPUT"
5252
fi
5353
- name: Configure AWS Production credentials
5454
if: env.PUSH_IMAGE_TO_PRODUCTION == 'true'
@@ -60,11 +60,11 @@ jobs:
6060
if: env.PUSH_IMAGE_TO_PRODUCTION == 'true'
6161
id: check-prod-image
6262
run: |
63-
if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids imageTag=$git_ref > /dev/null 2>&1; then
63+
if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids "imageTag=$git_ref" > /dev/null 2>&1; then
6464
echo "Production image with given tag already exists"
6565
else
6666
echo "Production image does not exist. Build needed"
67-
echo "${{ matrix.image_type }}-build-needed=true" >> $GITHUB_OUTPUT
67+
echo "${{ matrix.image_type }}-build-needed=true" >> "$GITHUB_OUTPUT"
6868
fi
6969
define-matrix:
7070
name: Determine AWS roles to push the image
@@ -76,10 +76,10 @@ jobs:
7676
- name: Set aws roles
7777
id: determine-aws-roles
7878
run: |
79-
if [ $PUSH_IMAGE_TO_PRODUCTION = 'true' ]; then
80-
echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure", "arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure"]' >> $GITHUB_OUTPUT
79+
if [ "$PUSH_IMAGE_TO_PRODUCTION" = "true" ]; then
80+
echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure", "arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure"]' >> "$GITHUB_OUTPUT"
8181
else
82-
echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure"]' >> $GITHUB_OUTPUT
82+
echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure"]' >> "$GITHUB_OUTPUT"
8383
fi
8484
build:
8585
needs: check-image-presence

.github/workflows/create_dockerized_db.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
id: github-ref
7777
run: |
7878
git_ref=$(git rev-parse ${{ inputs.github_ref || github.ref_name == 'next' && 'origin/next' || github.ref_name }} )
79-
echo "ref=$git_ref" >> $GITHUB_OUTPUT
79+
echo "ref=$git_ref" >> "$GITHUB_OUTPUT"
8080
- name: Commit postgres container with database
8181
run: |
8282
docker commit database "${{ steps.login-ecr.outputs.registry }}/mavis/development/postgres_db:${{ steps.github-ref.outputs.ref }}"

.github/workflows/data-replication-pipeline.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ on:
3030
git_ref_to_deploy:
3131
description: Git ref to deploy, for example, a tag, branch name or commit SHA
3232
type: string
33-
required: true
33+
required: true
3434

3535
permissions: {}
3636

@@ -72,7 +72,7 @@ jobs:
7272
ref: ${{ env.git_ref_to_deploy }}
7373
- name: Get git sha
7474
id: get-git-sha
75-
run: echo "git-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
75+
run: echo "git-sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
7676

7777
build-and-push-image:
7878
permissions:
@@ -106,7 +106,7 @@ jobs:
106106
--image-ids imageTag=${{ needs.determine-git-sha.outputs.git-sha }} \
107107
--query 'imageDetails[0].imageDigest' \
108108
--output text)
109-
echo "digest=$digest" >> $GITHUB_OUTPUT
109+
echo "digest=$digest" >> "$GITHUB_OUTPUT"
110110
- name: Parse environment variables
111111
id: parse-environment-variables
112112
env:
@@ -191,7 +191,7 @@ jobs:
191191
run: |
192192
file_path="${{ runner.temp }}/data-replication-task-definition.json"
193193
family_name="mavis-data-replication-task-definition-$environment"
194-
echo "$(jq --arg f "$family_name" '.family = $f' "$file_path")" > "$file_path"
194+
jq --arg f "$family_name" '.family = $f' "$file_path" > tmpfile && mv tmpfile "$file_path"
195195
- name: Deploy data-replication service
196196
id: ecs-deploy
197197
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
@@ -203,7 +203,7 @@ jobs:
203203
wait-for-service-stability: true
204204
- name: Check if deployment was successful
205205
run: |
206-
current_task_definition_arn=$(aws ecs describe-services --cluster mavis-$environment-data-replication --services mavis-$environment-data-replication --query services[0].deployments[0].taskDefinition | jq -r ".")
206+
current_task_definition_arn=$(aws ecs describe-services --cluster "mavis-$environment-data-replication" --services "mavis-$environment-data-replication" --query services[0].deployments[0].taskDefinition | jq -r ".")
207207
new_task_definition_arn=${{ steps.ecs-deploy.outputs.task-definition-arn }}
208208
echo "Current task definition arn: $current_task_definition_arn"
209209
echo "Expected task definition arn after deployment: $new_task_definition_arn"

.github/workflows/deploy.yml

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
ref: ${{ inputs.git_ref_to_deploy || github.sha }}
8181
- name: Get git sha
8282
id: get-git-sha
83-
run: echo "git-sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
83+
run: echo "git-sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
8484
build-and-push-images:
8585
permissions:
8686
id-token: write
@@ -117,11 +117,11 @@ jobs:
117117
image_tag: ${{ needs.determine-git-sha.outputs.git-sha }}
118118
run: |
119119
digest=$(aws ecr describe-images \
120-
--repository-name $repository_name \
121-
--image-ids imageTag=$image_tag \
120+
--repository-name "$repository_name" \
121+
--image-ids "imageTag=$image_tag" \
122122
--query 'imageDetails[0].imageDigest' \
123123
--output text)
124-
echo "digest=$digest" >> $GITHUB_OUTPUT
124+
echo "digest=$digest" >> "$GITHUB_OUTPUT"
125125
- name: Populate task definition
126126
id: create-task-definition
127127
uses: aws-actions/amazon-ecs-render-task-definition@v1
@@ -195,29 +195,29 @@ jobs:
195195
run: |
196196
family_name="mavis-migration-task-definition-$environment"
197197
file_path="${{ runner.temp }}/migration-task-definition.json"
198-
echo "$(jq --arg f "$family_name" '.family = $f' "${{ runner.temp }}/ops-task-definition.json")" > "$file_path"
198+
jq --arg f "$family_name" '.family = $f' "${{ runner.temp }}/ops-task-definition.json" > "$file_path"
199199
task_definition_arn=$(aws ecs register-task-definition \
200200
--cli-input-json file://$file_path \
201201
--query 'taskDefinition.taskDefinitionArn' \
202202
--output text
203203
)
204-
echo "task_definition_arn=$task_definition_arn" >> $GITHUB_OUTPUT
204+
echo "task_definition_arn=$task_definition_arn" >> "$GITHUB_OUTPUT"
205205
- name: Run schema migrations
206206
id: run-schema-migrations
207207
env:
208208
SLACK_MAVIS_RELEASES_WEBHOOK_URL: ${{ secrets.SLACK_MAVIS_RELEASES_WEBHOOK_URL }}
209209
run: |
210210
TASK_DEFINITION_ARN=${{ steps.register-migration-task-definition.outputs.task_definition_arn }}
211-
SUBNET_ID=$(aws ec2 describe-subnets --filters Name=tag:Name,Values=private-subnet-$environment-a --query 'Subnets[0].SubnetId' --output text)
212-
SECURITY_GROUP_ID=$(aws ec2 describe-security-groups --filters Name=group-name,Values=ops-service-$environment --query 'SecurityGroups[0].GroupId' --output text)
213-
211+
SUBNET_ID=$(aws ec2 describe-subnets --filters "Name=tag:Name,Values=private-subnet-$environment-a" --query 'Subnets[0].SubnetId' --output text)
212+
SECURITY_GROUP_ID=$(aws ec2 describe-security-groups --filters "Name=group-name,Values=ops-service-$environment" --query 'SecurityGroups[0].GroupId' --output text)
213+
214214
MAX_ATTEMPTS=3
215215
ATTEMPT=1
216216
217217
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
218218
TASK_ARN=$(aws ecs run-task \
219-
--cluster $cluster_name \
220-
--task-definition $TASK_DEFINITION_ARN \
219+
--cluster "$cluster_name" \
220+
--task-definition "$TASK_DEFINITION_ARN" \
221221
--launch-type FARGATE \
222222
--network-configuration "awsvpcConfiguration={subnets=[$SUBNET_ID],securityGroups=[$SECURITY_GROUP_ID]}" \
223223
--overrides '{
@@ -228,49 +228,51 @@ jobs:
228228
}' \
229229
--query 'tasks[0].taskArn' \
230230
--output text)
231-
231+
232232
echo "Waiting for task to complete: $TASK_ARN"
233-
TASK_ID=$(sed 's:^.*/::' <<< $TASK_ARN)
233+
234+
# shellcheck disable=SC2001
235+
TASK_ID=$(sed 's:^.*/::' <<< "$TASK_ARN")
234236
AWS_CONSOLE_URL="https://eu-west-2.console.aws.amazon.com/ecs/v2/clusters/$cluster_name/tasks/$TASK_ID/logs"
235-
237+
236238
echo "View logs in AWS Console: $AWS_CONSOLE_URL"
237-
if [ $environment = 'production' ]; then
239+
if [ "$environment" = 'production' ]; then
238240
./.github/send_slack_notification.sh "${{ secrets.SLACK_MAVIS_RELEASES_WEBHOOK_URL }}" "$AWS_CONSOLE_URL" "Running schema migrations attempt $ATTEMPT/$MAX_ATTEMPTS"
239241
fi
240242
241243
MAX_WAIT_TIME=3600
242244
POLL_INTERVAL=10 # Poll every 10 seconds
243245
ELAPSED=0
244246
245-
while [ $ELAPSED -lt $MAX_WAIT_TIME ]; do
247+
while [ "$ELAPSED" -lt "$MAX_WAIT_TIME" ]; do
246248
TASK_STATUS=$(aws ecs describe-tasks \
247-
--cluster $cluster_name \
248-
--tasks $TASK_ID \
249+
--cluster "$cluster_name" \
250+
--tasks "$TASK_ID" \
249251
--query 'tasks[0].lastStatus' \
250252
--output text)
251-
253+
252254
if [ "$TASK_STATUS" = "STOPPED" ]; then
253255
echo "Task has stopped"
254256
break
255257
fi
256-
257-
sleep $POLL_INTERVAL
258+
259+
sleep "$POLL_INTERVAL"
258260
ELAPSED=$((ELAPSED + POLL_INTERVAL))
259261
done
260262
261-
if [ $ELAPSED -ge $MAX_WAIT_TIME ]; then
263+
if [ "$ELAPSED" -ge "$MAX_WAIT_TIME" ]; then
262264
echo "ERROR: Migration task did not complete within $MAX_WAIT_TIME seconds."
263265
exit 1
264266
fi
265-
267+
266268
EXIT_CODE=$(aws ecs describe-tasks \
267-
--cluster $cluster_name \
268-
--tasks $TASK_ARN \
269+
--cluster "$cluster_name" \
270+
--tasks "$TASK_ARN" \
269271
--query 'tasks[0].containers[0].exitCode' \
270272
--output text)
271-
273+
272274
echo "Container exit code: $EXIT_CODE"
273-
275+
274276
if [ "$EXIT_CODE" = "0" ]; then
275277
echo "Migrations completed"
276278
break
@@ -279,7 +281,7 @@ jobs:
279281
if [ "$ATTEMPT" = "$MAX_ATTEMPTS" ]; then
280282
exit 1
281283
fi
282-
ATTEMPT=$((ATTEMPT+1))
284+
ATTEMPT=$((ATTEMPT+1))
283285
fi
284286
done
285287
- name: Notify migrations completed
@@ -294,7 +296,7 @@ jobs:
294296
- type: "section"
295297
text:
296298
type: "mrkdwn"
297-
text: "Schema migrations finished successfully :white_check_mark:"
299+
text: "Schema migrations finished successfully :white_check_mark:"
298300
deploy-service:
299301
name: Deploy service
300302
runs-on: ubuntu-latest
@@ -321,7 +323,7 @@ jobs:
321323
run: |
322324
file_path="${{ runner.temp }}/${{ matrix.service }}-task-definition.json"
323325
family_name="mavis-${{ matrix.service }}-task-definition-$environment"
324-
echo "$(jq --arg f "$family_name" '.family = $f' "$file_path")" > "$file_path"
326+
jq --arg f "$family_name" '.family = $f' "$file_path" > tmpfile && mv tmpfile "$file_path"
325327
- name: Deploy ${{ matrix.service }} service
326328
id: ecs-deploy
327329
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
@@ -333,7 +335,7 @@ jobs:
333335
wait-for-service-stability: true
334336
- name: Check if deployment was successful
335337
run: |
336-
current_task_definition_arn=$(aws ecs describe-services --cluster mavis-$environment --services mavis-$environment-${{ matrix.service }} --query services[0].deployments[0].taskDefinition | jq -r ".")
338+
current_task_definition_arn=$(aws ecs describe-services --cluster "mavis-$environment" --services "mavis-$environment-${{ matrix.service }}" --query services[0].deployments[0].taskDefinition | jq -r ".")
337339
new_task_definition_arn=${{ steps.ecs-deploy.outputs.task-definition-arn }}
338340
echo "Current task definition arn: $current_task_definition_arn"
339341
echo "Expected task definition arn after deployment: $new_task_definition_arn"
@@ -348,7 +350,7 @@ jobs:
348350
if: ${{ !cancelled() && inputs.environment == 'production' }}
349351
steps:
350352
- name: Notify deployment success
351-
if: ${{ needs.deploy-service.result == 'success' }}
353+
if: ${{ needs.deploy-service.result == 'success' }}
352354
uses: slackapi/slack-github-action@91efab103c0de0a537f72a35f6b8cda0ee76bf0a
353355
with:
354356
webhook: ${{ secrets.SLACK_MAVIS_RELEASES_WEBHOOK_URL }}

0 commit comments

Comments
 (0)