Skip to content

Commit 4a14f7d

Browse files
committed
common workflow for build and push
1 parent fcdd04d commit 4a14f7d

File tree

4 files changed

+67
-198
lines changed

4 files changed

+67
-198
lines changed

.github/workflows/build_nhsd_git_secrets.yml renamed to .github/workflows/build_and_push_docker_image.yml

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
1-
name: Build nhsd git secrets
1+
name: Build and push docker image
22

33
on:
44
workflow_call:
55
secrets:
6-
SONAR_TOKEN:
7-
required: false
86
PUSH_IMAGE_ROLE:
97
required: true
108
inputs:
11-
git_secrets_container_ecr:
9+
container_ecr:
10+
type: string
11+
description: "The name of the ECR repository to push the container image to."
12+
required: true
13+
container_image_tag:
1214
type: string
13-
description: "The name of the ECR repository to push the dev container image to."
15+
description: "The tag to use for the container image."
1416
required: true
15-
git_secrets_container_image_tag:
17+
docker_file:
1618
type: string
17-
description: "The tag to use for the dev container image."
19+
description: "The Dockerfile to use for building the container image."
1820
required: true
21+
check_ecr_image_scan_results_script_tag:
22+
type: string
23+
description: "The tag to download check_ecr_image_scan_results.sh script."
24+
required: false
25+
default: "dev_container_build"
26+
1927
jobs:
20-
build_nhsd_git_secrets_x64:
28+
build_image_amd64:
2129
permissions:
2230
id-token: write
2331
runs-on: ubuntu-22.04
@@ -27,17 +35,19 @@ jobs:
2735
with:
2836
fetch-depth: 0
2937

30-
- name: Build dev container
38+
- name: Build container
3139
run: |
32-
docker build -f dockerfiles/nhsd-git-secrets.dockerfile -t nhsd-git-secrets-image .
40+
docker build -f "${DOCKER_FILE}" -t x64-image .
41+
env:
42+
DOCKER_FILE: ${{ inputs.docker_file }}
3343

3444
- name: Configure AWS Credentials
3545
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8
3646
id: connect-aws-deploy
3747
with:
3848
aws-region: eu-west-2
3949
role-to-assume: ${{ secrets.PUSH_IMAGE_ROLE }}
40-
role-session-name: dev-container-build-x64
50+
role-session-name: dev-container-build-amd64
4151
output-credentials: true
4252

4353
- name: Retrieve AWS Account ID
@@ -52,22 +62,26 @@ jobs:
5262
5363
- name: Push x64 image to Amazon ECR
5464
env:
55-
ECR_REPOSITORY: ${{ inputs.git_secrets_container_ecr }}
56-
IMAGE_TAG: ${{ inputs.git_secrets_container_image_tag }}
65+
ECR_REPOSITORY: ${{ inputs.container_ecr }}
66+
IMAGE_TAG: ${{ inputs.container_image_tag }}
5767
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
5868
run: |
59-
docker tag "nhsd-git-secrets-image" "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64"
69+
docker tag "amd64-image" "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64"
6070
docker push "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64"
71+
6172
- name: Check dev container scan results
6273
env:
63-
REPOSITORY_NAME: ${{ inputs.git_secrets_container_ecr }}
64-
IMAGE_TAG: ${{ inputs.git_secrets_container_image_tag }}-amd64
74+
REPOSITORY_NAME: ${{ inputs.container_ecr }}
75+
IMAGE_TAG: ${{ inputs.container_image_tag }}-amd64
6576
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
77+
SCRIPT_TAG: ${{ inputs.check_ecr_image_scan_results_script_tag }}
6678
run: |
79+
curl -L "https://raw.githubusercontent.com/NHSDigital/eps-common-workflows/refs/heads/${SCRIPT_TAG}/.github/scripts/check_ecr_image_scan_results.sh" -o /tmp/check_ecr_image_scan_results.sh
80+
chmod +x /tmp/check_ecr_image_scan_results.sh
6781
sleep 30
68-
./.github/scripts/check_ecr_image_scan_results.sh
82+
/tmp/check_ecr_image_scan_results.sh
6983
70-
build_nhsd_git_secrets_arm64:
84+
build_image_arm64:
7185
permissions:
7286
id-token: write
7387
runs-on: ubuntu-22.04-arm
@@ -77,9 +91,11 @@ jobs:
7791
with:
7892
fetch-depth: 0
7993

80-
- name: Build dev container
94+
- name: Build container
8195
run: |
82-
docker build -f dockerfiles/nhsd-git-secrets.dockerfile -t nhsd-git-secrets-image-arm .
96+
docker build -f "${DOCKER_FILE}" -t arm64-image .
97+
env:
98+
DOCKER_FILE: ${{ inputs.docker_file }}
8399

84100
- name: Configure AWS Credentials
85101
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8
@@ -102,27 +118,29 @@ jobs:
102118
103119
- name: Push ARM64 image to Amazon ECR
104120
env:
105-
ECR_REPOSITORY: ${{ inputs.git_secrets_container_ecr }}
106-
IMAGE_TAG: ${{ inputs.git_secrets_container_image_tag }}
121+
ECR_REPOSITORY: ${{ inputs.container_ecr }}
122+
IMAGE_TAG: ${{ inputs.container_image_tag }}
107123
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
108124
run: |
109-
docker tag "nhsd-git-secrets-image-arm" "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64"
125+
docker tag "arm64-image" "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64"
110126
docker push "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64"
111127
- name: Check dev container scan results
112128
env:
113-
REPOSITORY_NAME: ${{ inputs.git_secrets_container_ecr }}
114-
IMAGE_TAG: ${{ inputs.git_secrets_container_image_tag }}-arm64
129+
REPOSITORY_NAME: ${{ inputs.container_ecr }}
130+
IMAGE_TAG: ${{ inputs.container_image_tag }}-arm64
115131
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
132+
SCRIPT_TAG: ${{ inputs.check_ecr_image_scan_results_script_tag }}
116133
run: |
117-
# Wait a moment for ECR to process the new manifest
134+
curl -L "https://raw.githubusercontent.com/NHSDigital/eps-common-workflows/refs/heads/${SCRIPT_TAG}/.github/scripts/check_ecr_image_scan_results.sh" -o /tmp/check_ecr_image_scan_results.sh
135+
chmod +x /tmp/check_ecr_image_scan_results.sh
118136
sleep 30
119-
./.github/scripts/check_ecr_image_scan_results.sh
137+
/tmp/check_ecr_image_scan_results.sh
120138
121139
create_multi_arch_manifest:
122140
permissions:
123141
id-token: write
124142
runs-on: ubuntu-22.04
125-
needs: [build_nhsd_git_secrets_x64, build_nhsd_git_secrets_arm64]
143+
needs: [build_image_amd64, build_image_arm64]
126144
steps:
127145
- name: Set up Docker Buildx
128146
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
@@ -147,8 +165,8 @@ jobs:
147165
148166
- name: Create and push multi-architecture manifest for tag
149167
env:
150-
ECR_REPOSITORY: ${{ inputs.git_secrets_container_ecr }}
151-
IMAGE_TAG: ${{ inputs.git_secrets_container_image_tag }}
168+
ECR_REPOSITORY: ${{ inputs.container_ecr }}
169+
IMAGE_TAG: ${{ inputs.container_image_tag }}
152170
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
153171
run: |
154172
# Create manifest list combining both architectures
@@ -158,8 +176,8 @@ jobs:
158176
159177
- name: Verify multi-architecture manifest
160178
env:
161-
ECR_REPOSITORY: ${{ inputs.git_secrets_container_ecr }}
162-
IMAGE_TAG: ${{ inputs.git_secrets_container_image_tag }}
179+
ECR_REPOSITORY: ${{ inputs.container_ecr }}
180+
IMAGE_TAG: ${{ inputs.container_image_tag }}
163181
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
164182
run: |
165183
echo "=== Verifying multi-architecture manifest ==="

.github/workflows/pull_request.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,12 @@ jobs:
8484
PUSH_IMAGE_ROLE: ${{ secrets.DEV_CONTAINER_PUSH_IMAGE_ROLE }}
8585

8686
build_nhsd_git_secrets:
87-
uses: ./.github/workflows/build_nhsd_git_secrets.yml
87+
uses: ./.github/workflows/build_and_push_docker_image.yml
8888
needs: [get_asdf_version, get_issue_number_and_commit_id]
8989
with:
90-
git_secrets_container_ecr: git-secrets
91-
git_secrets_container_image_tag: PR-${{ needs.get_issue_number_and_commit_id.outputs.issue_number }}-${{ needs.get_issue_number_and_commit_id.outputs.sha_short }}-nhsd-git-secrets
90+
container_ecr: git-secrets
91+
container_image_tag: PR-${{ needs.get_issue_number_and_commit_id.outputs.issue_number }}-${{ needs.get_issue_number_and_commit_id.outputs.sha_short }}-nhsd-git-secrets
92+
docker_file: dockerfiles/nhsd-git-secrets.dockerfile
9293
secrets:
9394
PUSH_IMAGE_ROLE: ${{ secrets.DEV_CONTAINER_PUSH_IMAGE_ROLE }}
9495

.github/workflows/quality-checks.yml

Lines changed: 9 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -420,163 +420,12 @@ jobs:
420420
name: cfn_guard_output
421421
path: cfn_guard_output
422422

423-
build_dev_container_x64:
424-
permissions:
425-
id-token: write
426-
runs-on: ubuntu-22.04
427-
steps:
428-
- name: Checkout code
429-
uses: actions/checkout@v5
430-
with:
431-
fetch-depth: 0
432-
433-
- name: Download check_ecr_image_scan_results.sh script
434-
env:
435-
SCRIPT_TAG: ${{ inputs.check_ecr_image_scan_results_script_tag }}
436-
run: |
437-
curl -L "https://raw.githubusercontent.com/NHSDigital/eps-workflow-quality-checks/refs/heads/${SCRIPT_TAG}/.github/scripts/check_ecr_image_scan_results.sh" -o check_ecr_image_scan_results.sh
438-
chmod +x check_ecr_image_scan_results.sh
439-
- name: Build dev container
440-
run: |
441-
docker build -f .devcontainer/Dockerfile -t dev-container-image .
442-
443-
- name: Configure AWS Credentials
444-
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8
445-
id: connect-aws-deploy
446-
with:
447-
aws-region: eu-west-2
448-
role-to-assume: ${{ secrets.PUSH_IMAGE_ROLE }}
449-
role-session-name: dev-container-build-x64
450-
output-credentials: true
451-
452-
- name: Retrieve AWS Account ID
453-
id: retrieve-deploy-account-id
454-
run: |
455-
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
456-
echo "account_id=$ACCOUNT_ID" >> "$GITHUB_OUTPUT"
457-
458-
- name: Login to Amazon ECR
459-
run: |
460-
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ steps.retrieve-deploy-account-id.outputs.account_id }}.dkr.ecr.eu-west-2.amazonaws.com
461-
462-
- name: Push x64 image to Amazon ECR
463-
env:
464-
ECR_REPOSITORY: ${{ inputs.dev_container_ecr }}
465-
IMAGE_TAG: ${{ inputs.dev_container_image_tag }}
466-
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
467-
run: |
468-
docker tag "dev-container-image" "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64"
469-
docker push "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64"
470-
- name: Check dev container scan results
471-
env:
472-
REPOSITORY_NAME: ${{ inputs.dev_container_ecr }}
473-
IMAGE_TAG: ${{ inputs.dev_container_image_tag }}-amd64
474-
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
475-
run: |
476-
sleep 30
477-
./check_ecr_image_scan_results.sh
478-
479-
build_dev_container_arm64:
480-
permissions:
481-
id-token: write
482-
runs-on: ubuntu-22.04-arm
483-
steps:
484-
- name: Checkout code
485-
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
486-
with:
487-
fetch-depth: 0
488-
489-
- name: Download check_ecr_image_scan_results.sh script
490-
env:
491-
SCRIPT_TAG: ${{ inputs.check_ecr_image_scan_results_script_tag }}
492-
run: |
493-
curl -L "https://raw.githubusercontent.com/NHSDigital/eps-common-workflows/refs/heads/${SCRIPT_TAG}/.github/scripts/check_ecr_image_scan_results.sh" -o check_ecr_image_scan_results.sh
494-
chmod +x check_ecr_image_scan_results.sh
495-
496-
- name: Build dev container
497-
run: |
498-
docker build -f .devcontainer/Dockerfile -t dev-container-image-arm .
499-
500-
- name: Configure AWS Credentials
501-
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8
502-
id: connect-aws-deploy
503-
with:
504-
aws-region: eu-west-2
505-
role-to-assume: ${{ secrets.PUSH_IMAGE_ROLE }}
506-
role-session-name: dev-container-build-arm64
507-
output-credentials: true
508-
509-
- name: Retrieve AWS Account ID
510-
id: retrieve-deploy-account-id
511-
run: |
512-
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
513-
echo "account_id=$ACCOUNT_ID" >> "$GITHUB_OUTPUT"
514-
515-
- name: Login to Amazon ECR
516-
run: |
517-
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ steps.retrieve-deploy-account-id.outputs.account_id }}.dkr.ecr.eu-west-2.amazonaws.com
518-
519-
- name: Push ARM64 image to Amazon ECR
520-
env:
521-
ECR_REPOSITORY: ${{ inputs.dev_container_ecr }}
522-
IMAGE_TAG: ${{ inputs.dev_container_image_tag }}
523-
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
524-
run: |
525-
docker tag "dev-container-image-arm" "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64"
526-
docker push "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64"
527-
- name: Check dev container scan results
528-
env:
529-
REPOSITORY_NAME: ${{ inputs.dev_container_ecr }}
530-
IMAGE_TAG: ${{ inputs.dev_container_image_tag }}-arm64
531-
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
532-
run: |
533-
# Wait a moment for ECR to process the new manifest
534-
sleep 30
535-
./check_ecr_image_scan_results.sh
536-
537-
create_multi_arch_manifest:
538-
permissions:
539-
id-token: write
540-
runs-on: ubuntu-22.04
541-
needs: [build_dev_container_x64, build_dev_container_arm64]
542-
steps:
543-
- name: Set up Docker Buildx
544-
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435
545-
546-
- name: Configure AWS Credentials
547-
uses: aws-actions/configure-aws-credentials@00943011d9042930efac3dcd3a170e4273319bc8
548-
with:
549-
aws-region: eu-west-2
550-
role-to-assume: ${{ secrets.PUSH_IMAGE_ROLE }}
551-
role-session-name: multi-arch-manifest
552-
output-credentials: true
553-
554-
- name: Retrieve AWS Account ID
555-
id: retrieve-deploy-account-id
556-
run: |
557-
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
558-
echo "account_id=$ACCOUNT_ID" >> "$GITHUB_OUTPUT"
559-
560-
- name: Login to Amazon ECR
561-
run: |
562-
aws ecr get-login-password --region eu-west-2 | docker login --username AWS --password-stdin ${{ steps.retrieve-deploy-account-id.outputs.account_id }}.dkr.ecr.eu-west-2.amazonaws.com
563-
564-
- name: Create and push multi-architecture manifest for tag
565-
env:
566-
ECR_REPOSITORY: ${{ inputs.dev_container_ecr }}
567-
IMAGE_TAG: ${{ inputs.dev_container_image_tag }}
568-
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
569-
run: |
570-
# Create manifest list combining both architectures
571-
docker buildx imagetools create -t "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}" \
572-
"${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-amd64" \
573-
"${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}-arm64"
574-
575-
- name: Verify multi-architecture manifest
576-
env:
577-
ECR_REPOSITORY: ${{ inputs.dev_container_ecr }}
578-
IMAGE_TAG: ${{ inputs.dev_container_image_tag }}
579-
ACCOUNT_ID: ${{ steps.retrieve-deploy-account-id.outputs.account_id }}
580-
run: |
581-
echo "=== Verifying multi-architecture manifest ==="
582-
docker buildx imagetools inspect "${ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/${ECR_REPOSITORY}:${IMAGE_TAG}"
423+
build_and_push_dev_container_image:
424+
uses: ./.github/workflows/build_and_push_docker_image.yml
425+
with:
426+
container_ecr: ${{ inputs.dev_container_ecr }}
427+
container_image_tag: ${{ inputs.dev_container_image_tag }}
428+
docker_file: ".devcontainer/Dockerfile"
429+
check_ecr_image_scan_results_script_tag: ${{ inputs.check_ecr_image_scan_results_script_tag }}
430+
secrets:
431+
PUSH_IMAGE_ROLE: ${{ secrets.PUSH_IMAGE_ROLE }}

.github/workflows/release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ jobs:
5454
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
5555
PUSH_IMAGE_ROLE: ${{ secrets.DEV_CONTAINER_PUSH_IMAGE_ROLE }}
5656
build_nhsd_git_secrets:
57-
uses: ./.github/workflows/build_nhsd_git_secrets.yml
57+
uses: ./.github/workflows/build_and_push_docker_image.yml
5858
needs: [get_asdf_version, get_commit_id]
5959
with:
60-
git_secrets_container_ecr: git-secrets
61-
git_secrets_container_image_tag: release-${{ needs.get_commit_id.outputs.sha_short }}
60+
container_ecr: git-secrets
61+
container_image_tag: release-${{ needs.get_commit_id.outputs.sha_short }}
62+
docker_file: dockerfiles/nhsd-git-secrets.dockerfile
6263
secrets:
6364
PUSH_IMAGE_ROLE: ${{ secrets.DEV_CONTAINER_PUSH_IMAGE_ROLE }}
6465
tag_release:

0 commit comments

Comments
 (0)