Skip to content

Commit 69c838b

Browse files
Merge pull request #6126 from NHSDigital/MAV-3850/speedup_deployment_to_testing_environments
Speed up deployment to testing environments
2 parents 34bf20e + 31ddc5a commit 69c838b

3 files changed

Lines changed: 55 additions & 58 deletions

File tree

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

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -89,53 +89,24 @@ jobs:
8989
echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure"]' >> "$GITHUB_OUTPUT"
9090
fi
9191
# yamllint enable rule:line-length
92-
build:
93-
needs: check-image-presence
92+
build-and-push:
93+
needs: [check-image-presence, define-matrix]
9494
if: >-
9595
needs.check-image-presence.outputs.webapp-build-needed == 'true' ||
96-
needs.check-image-presence.outputs.ops-build-needed == 'true'
96+
needs.check-image-presence.outputs.ops-build-needed == 'true'
9797
runs-on: ubuntu-latest
9898
permissions:
9999
id-token: write
100+
strategy:
101+
matrix:
102+
aws-role: ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
100103
steps:
101104
- name: Checkout code
102105
uses: actions/checkout@v6
103106
with:
104107
ref: ${{ env.git_ref }}
105108
- name: Write build SHA
106109
run: git rev-parse HEAD > public/sha
107-
- name: Build webapp docker image
108-
run: docker build -t "mavis-webapp:latest" .
109-
- name: Save web image
110-
run: docker save -o image.tar mavis-webapp:latest
111-
- name: Upload web image
112-
uses: actions/upload-artifact@v7
113-
with:
114-
name: webapp-image
115-
path: image.tar
116-
- name: Build ops docker image
117-
run: docker build -f ops.Dockerfile -t "mavis-ops:latest" .
118-
- name: Save ops image
119-
run: docker save -o image.tar mavis-ops:latest
120-
- name: Upload ops image
121-
uses: actions/upload-artifact@v7
122-
with:
123-
name: ops-image
124-
path: image.tar
125-
push:
126-
runs-on: ubuntu-latest
127-
needs: [build, define-matrix]
128-
permissions:
129-
id-token: write
130-
strategy:
131-
matrix:
132-
aws-role: ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
133-
image_type: ["webapp", "ops"]
134-
steps:
135-
- name: Download Docker image
136-
uses: actions/download-artifact@v8
137-
with:
138-
name: ${{ matrix.image_type }}-image
139110
- name: Configure AWS Credentials
140111
uses: aws-actions/configure-aws-credentials@v6
141112
with:
@@ -144,13 +115,34 @@ jobs:
144115
- name: Login to ECR
145116
id: login-ecr
146117
uses: aws-actions/amazon-ecr-login@v2
147-
- name: Load Docker image
148-
run: docker load -i image.tar
149-
- name: Tag Docker image
150-
run: >-
151-
docker tag mavis-${{ matrix.image_type }}:latest "${{ steps.login-ecr.outputs.registry
152-
}}/mavis/${{ matrix.image_type }}":"$git_ref"
153-
- name: Push Docker image
154-
run: >-
155-
docker push "${{ steps.login-ecr.outputs.registry }}/mavis/${{ matrix.image_type
156-
}}":"$git_ref"
118+
- name: Set up Docker Buildx
119+
uses: docker/setup-buildx-action@v3
120+
# yamllint disable rule:line-length
121+
- name: Build and push webapp image
122+
if: needs.check-image-presence.outputs.webapp-build-needed == 'true'
123+
uses: docker/build-push-action@v6
124+
with:
125+
context: .
126+
push: true
127+
tags: ${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ env.git_ref }}
128+
cache-from:
129+
type=registry,ref=${{ steps.login-ecr.outputs.registry }}/mavis/webapp:buildcache
130+
cache-to:
131+
type=registry,ref=${{ steps.login-ecr.outputs.registry
132+
}}/mavis/webapp:buildcache,mode=max,image-manifest=true,oci-mediatypes=true
133+
- name: Build and push ops image
134+
if: needs.check-image-presence.outputs.ops-build-needed == 'true'
135+
uses: docker/build-push-action@v6
136+
with:
137+
context: .
138+
file: ops.Dockerfile
139+
push: true
140+
tags: ${{ steps.login-ecr.outputs.registry }}/mavis/ops:${{ env.git_ref }}
141+
build-args: |
142+
REPOSITORY=${{ steps.login-ecr.outputs.registry }}/mavis/webapp
143+
IMAGE_TAG=${{ env.git_ref }}
144+
cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/mavis/ops:buildcache
145+
cache-to:
146+
type=registry,ref=${{ steps.login-ecr.outputs.registry
147+
}}/mavis/ops:buildcache,mode=max,image-manifest=true,oci-mediatypes=true
148+
# yamllint enable rule:line-length

.github/workflows/continuous-deployment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
id-token: write
1313
uses: ./.github/workflows/test.yml
1414
deploy:
15-
needs: test
1615
strategy:
1716
fail-fast: false
1817
matrix:
@@ -23,6 +22,7 @@ jobs:
2322
with:
2423
environment: ${{ matrix.environment }}
2524
server_types: all
25+
run_pre_deploy_migrations: false
2626
end-to-end-tests:
2727
needs: [deploy]
2828
if: ${{ contains(needs.deploy.result, 'success') && github.ref_name == 'next' }}

.github/workflows/deploy.yml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ on:
1010
server_types:
1111
required: true
1212
type: string
13+
run_pre_deploy_migrations:
14+
required: false
15+
type: boolean
16+
default: true
1317
workflow_dispatch:
1418
inputs:
1519
git_ref_to_deploy:
@@ -42,6 +46,11 @@ on:
4246
- sidekiq
4347
- ops
4448
default: all
49+
run_pre_deploy_migrations:
50+
description: Run data migrations before service deployment.
51+
required: false
52+
type: boolean
53+
default: true
4554

4655
concurrency:
4756
group: deploy-${{ inputs.environment }}
@@ -57,8 +66,10 @@ env:
5766
app_version: ${{ inputs.git_ref_to_deploy == '' && github.ref_name || inputs.git_ref_to_deploy }}
5867

5968
jobs:
60-
validate-inputs:
69+
validate-and-resolve-sha:
6170
runs-on: ubuntu-latest
71+
outputs:
72+
git-sha: ${{ steps.get-git-sha.outputs.git-sha }}
6273
steps:
6374
- name: Validate inputs
6475
run: |
@@ -68,12 +79,6 @@ jobs:
6879
exit 1
6980
fi
7081
fi
71-
determine-git-sha:
72-
runs-on: ubuntu-latest
73-
needs: validate-inputs
74-
outputs:
75-
git-sha: ${{ steps.get-git-sha.outputs.git-sha }}
76-
steps:
7782
- name: Checkout code
7883
uses: actions/checkout@v6
7984
with:
@@ -84,14 +89,14 @@ jobs:
8489
build-and-push-images:
8590
permissions:
8691
id-token: write
87-
needs: determine-git-sha
92+
needs: validate-and-resolve-sha
8893
uses: ./.github/workflows/build-and-push-image.yml
8994
with:
90-
git_sha: ${{ needs.determine-git-sha.outputs.git-sha }}
95+
git_sha: ${{ needs.validate-and-resolve-sha.outputs.git-sha }}
9196
prepare-deployment:
9297
name: Prepare deployment
9398
runs-on: ubuntu-latest
94-
needs: [determine-git-sha, build-and-push-images]
99+
needs: [validate-and-resolve-sha, build-and-push-images]
95100
permissions:
96101
id-token: write
97102
strategy:
@@ -107,7 +112,7 @@ jobs:
107112
uses: actions/checkout@v6
108113
id: checkout-code
109114
with:
110-
ref: ${{ needs.determine-git-sha.outputs.git-sha }}
115+
ref: ${{ needs.validate-and-resolve-sha.outputs.git-sha }}
111116
- name: Configure AWS Credentials
112117
uses: aws-actions/configure-aws-credentials@v6
113118
with:
@@ -116,7 +121,7 @@ jobs:
116121
- name: Get image digest
117122
id: get-image-digest
118123
env:
119-
image_tag: ${{ needs.determine-git-sha.outputs.git-sha }}
124+
image_tag: ${{ needs.validate-and-resolve-sha.outputs.git-sha }}
120125
run: |
121126
digest=$(aws ecr describe-images \
122127
--repository-name "$repository_name" \

0 commit comments

Comments
 (0)