Skip to content

Commit fe43be3

Browse files
committed
Enhance deployment workflow for recordprocessor image management
- Added a new job to resolve existing recordprocessor image tags when not building a new image, improving flexibility in deployment. - Updated job dependencies to ensure proper sequencing between building and resolving image tags. - Refined output handling for `recordprocessor_image_tag` to accommodate both build and resolve scenarios, enhancing clarity in image management.
1 parent 1450b4f commit fe43be3

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

.github/workflows/deploy-backend.yml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ run-name: Deploy Backend - ${{ inputs.environment }} ${{ inputs.sub_environment
6161

6262
jobs:
6363
build-and-push-recordprocessor:
64+
if: ${{ inputs.build_recordprocessor_image }}
6465
permissions:
6566
id-token: write
6667
contents: read
6768
outputs:
68-
recordprocessor_image_tag: ${{ steps.build-image.outputs.recordprocessor_image_tag || steps.resolve-image-tag.outputs.recordprocessor_image_tag }}
69+
recordprocessor_image_tag: ${{ steps.build-image.outputs.recordprocessor_image_tag }}
6970
name: Build and push recordprocessor image
7071
runs-on: ubuntu-latest
7172

@@ -88,13 +89,11 @@ jobs:
8889
role-session-name: github-actions
8990

9091
- name: Login to Amazon ECR
91-
if: ${{ inputs.build_recordprocessor_image }}
9292
id: login-ecr
9393
uses: aws-actions/amazon-ecr-login@062b18b96a7aff071d4dc91bc00c4c1a7945b076
9494

9595
- name: Build and push Docker image
9696
id: build-image
97-
if: ${{ inputs.build_recordprocessor_image }}
9897
env:
9998
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
10099
working-directory: lambdas
@@ -107,9 +106,29 @@ jobs:
107106
docker push "${IMAGE_URI}"
108107
echo "recordprocessor_image_tag=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
109108
109+
resolve-recordprocessor-image-tag:
110+
if: ${{ !inputs.build_recordprocessor_image }}
111+
permissions:
112+
id-token: write
113+
contents: read
114+
outputs:
115+
recordprocessor_image_tag: ${{ steps.resolve-image-tag.outputs.recordprocessor_image_tag }}
116+
name: Resolve existing recordprocessor image tag
117+
runs-on: ubuntu-latest
118+
environment:
119+
name: ${{ inputs.environment }}
120+
env:
121+
AWS_REGION: eu-west-2
122+
steps:
123+
- name: Connect to AWS
124+
uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
125+
with:
126+
aws-region: eu-west-2
127+
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
128+
role-session-name: github-actions
129+
110130
- name: Resolve latest matching recordprocessor image tag
111131
id: resolve-image-tag
112-
if: ${{ !inputs.build_recordprocessor_image }}
113132
env:
114133
REPOSITORY_NAME: imms-recordprocessor-repo
115134
TAG_PREFIX: ${{ inputs.sub_environment }}-
@@ -139,10 +158,15 @@ jobs:
139158
permissions:
140159
id-token: write
141160
contents: read
142-
needs: build-and-push-recordprocessor
161+
needs:
162+
- build-and-push-recordprocessor
163+
- resolve-recordprocessor-image-tag
164+
if: ${{ !cancelled() && (needs.build-and-push-recordprocessor.result == 'success' || needs.resolve-recordprocessor-image-tag.result == 'success') }}
165+
outputs:
166+
recordprocessor_image_tag: ${{ needs.build-and-push-recordprocessor.outputs.recordprocessor_image_tag || needs.resolve-recordprocessor-image-tag.outputs.recordprocessor_image_tag }}
143167
runs-on: ubuntu-latest
144168
env:
145-
TF_VAR_recordprocessor_image_tag: ${{ needs.build-and-push-recordprocessor.outputs.recordprocessor_image_tag }}
169+
TF_VAR_recordprocessor_image_tag: ${{ needs.build-and-push-recordprocessor.outputs.recordprocessor_image_tag || needs.resolve-recordprocessor-image-tag.outputs.recordprocessor_image_tag }}
146170
environment:
147171
name: ${{ inputs.environment }}
148172
steps:
@@ -184,7 +208,7 @@ jobs:
184208
needs: terraform-plan
185209
runs-on: ubuntu-latest
186210
env:
187-
TF_VAR_recordprocessor_image_tag: ${{ needs.build-and-push-recordprocessor.outputs.recordprocessor_image_tag }}
211+
TF_VAR_recordprocessor_image_tag: ${{ needs.terraform-plan.outputs.recordprocessor_image_tag }}
188212
environment:
189213
name: ${{ inputs.environment }}
190214
steps:

0 commit comments

Comments
 (0)