Skip to content

Commit 94c502a

Browse files
committed
Add support for conditional recordprocessor image builds in deployment workflows
- Introduced a new input parameter `build_recordprocessor_image` in the deployment workflows to control the building of the recordprocessor Docker image. - Updated the `deploy-backend.yml` to include logic for building the image based on changes detected in the PR. - Added a new job in `pr-deploy-and-test.yml` to detect changes in the recordprocessor directory, influencing the deployment process. - Enhanced the handling of image tags to default to 'latest' if no build is triggered, improving deployment flexibility.
1 parent 9a90419 commit 94c502a

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

.github/workflows/continuous-deployment.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: ./.github/workflows/deploy-backend.yml
2121
with:
2222
apigee_environment: internal-dev
23+
build_recordprocessor_image: true
2324
create_mns_subscription: true
2425
environment: dev
2526
sub_environment: internal-dev
@@ -82,6 +83,7 @@ jobs:
8283
uses: ./.github/workflows/deploy-backend.yml
8384
with:
8485
apigee_environment: ${{ matrix.sub_environment_name }}
86+
build_recordprocessor_image: true
8587
create_mns_subscription: true
8688
environment: dev
8789
sub_environment: ${{ matrix.sub_environment_name }}

.github/workflows/deploy-backend.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
apigee_environment:
77
required: true
88
type: string
9+
build_recordprocessor_image:
10+
required: false
11+
type: boolean
12+
default: false
913
create_mns_subscription:
1014
required: false
1115
type: boolean
@@ -39,6 +43,11 @@ on:
3943
- dev
4044
- preprod
4145
- prod
46+
build_recordprocessor_image:
47+
description: Build and push a new recordprocessor image for this deployment
48+
required: false
49+
type: boolean
50+
default: false
4251
sub_environment:
4352
type: string
4453
description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments
@@ -70,17 +79,20 @@ jobs:
7079
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
7180

7281
- name: Connect to AWS
82+
if: ${{ inputs.build_recordprocessor_image }}
7383
uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
7484
with:
7585
aws-region: eu-west-2
7686
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
7787
role-session-name: github-actions
7888

7989
- name: Login to Amazon ECR
90+
if: ${{ inputs.build_recordprocessor_image }}
8091
id: login-ecr
8192
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076
8293

8394
- name: Build and push Docker image
95+
if: ${{ inputs.build_recordprocessor_image }}
8496
env:
8597
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
8698
working-directory: lambdas
@@ -92,14 +104,18 @@ jobs:
92104
docker build -f recordprocessor/Dockerfile -t "${IMAGE_URI}" .
93105
docker push "${IMAGE_URI}"
94106
107+
- name: Skip image build
108+
if: ${{ !inputs.build_recordprocessor_image }}
109+
run: echo "No recordprocessor changes detected and no manual override provided. Skipping image build."
110+
95111
terraform-plan:
96112
permissions:
97113
id-token: write
98114
contents: read
99115
needs: build-and-push-recordprocessor
100116
runs-on: ubuntu-latest
101117
env:
102-
TF_VAR_recordprocessor_image_tag: ${{ github.sha }}
118+
TF_VAR_recordprocessor_image_tag: ${{ inputs.build_recordprocessor_image && github.sha || 'latest' }}
103119
environment:
104120
name: ${{ inputs.environment }}
105121
steps:
@@ -141,7 +157,7 @@ jobs:
141157
needs: terraform-plan
142158
runs-on: ubuntu-latest
143159
env:
144-
TF_VAR_recordprocessor_image_tag: ${{ github.sha }}
160+
TF_VAR_recordprocessor_image_tag: ${{ inputs.build_recordprocessor_image && github.sha || 'latest' }}
145161
environment:
146162
name: ${{ inputs.environment }}
147163
steps:

.github/workflows/pr-deploy-and-test.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,38 @@ concurrency:
99
cancel-in-progress: true
1010

1111
jobs:
12+
detect-recordprocessor-changes:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
has_changes: ${{ steps.detect.outputs.has_changes }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Detect recordprocessor changes in PR
23+
id: detect
24+
run: |
25+
git fetch origin "${{ github.event.pull_request.base.ref }}"
26+
27+
if git diff --name-only "origin/${{ github.event.pull_request.base.ref }}" "${{ github.sha }}" | grep -q '^lambdas/recordprocessor/'; then
28+
echo "has_changes=true" >> "$GITHUB_OUTPUT"
29+
else
30+
echo "has_changes=false" >> "$GITHUB_OUTPUT"
31+
fi
32+
1233
run-quality-checks:
1334
uses: ./.github/workflows/quality-checks.yml
1435
secrets:
1536
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
1637

1738
deploy-pr-backend:
18-
needs: [run-quality-checks]
39+
needs: [run-quality-checks, detect-recordprocessor-changes]
1940
uses: ./.github/workflows/deploy-backend.yml
2041
with:
2142
apigee_environment: internal-dev
43+
build_recordprocessor_image: ${{ github.event.action == 'opened' || needs.detect-recordprocessor-changes.outputs.has_changes == 'true' }}
2244
create_mns_subscription: true
2345
environment: dev
2446
sub_environment: pr-${{github.event.pull_request.number}}

0 commit comments

Comments
 (0)