Skip to content

Commit 7bfbb53

Browse files
fix(ci): deploy PR environments by commit SHA so every push rolls out
Ports bcgov/nr-csp#122 (itself a port of bcgov/quickstart-openshift#2817). PR images are tagged with the PR number, which is reused on every push. A repeat push rebuilds the image under the same tag, so oc apply sees an unchanged Deployment - no pods restart and the stale image keeps serving despite imagePullPolicy: Always. Builds now push each image under two tags: the PR number (mutable, still what merge.yml deploys to test) and the immutable head commit SHA. PR deploys pass the head SHA as IMAGE_TAG, so every push changes the pod spec and forces a fresh rollout. Test deploys are unaffected: the PR-number tag is unique per merge, so the spec changes there anyway.
1 parent 13e8be2 commit 7bfbb53

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

.github/workflows/pr-open.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ jobs:
3838
- uses: bcgov/action-builder-ghcr@cb2629351c87dd1c2130073e4ebb7233a9653a63 # v4.4.1
3939
with:
4040
package: ${{ matrix.package }}
41-
tags: ${{ github.event.number }}
41+
# The PR tag is mutable (reused every push) and is what merge.yml
42+
# deploys/promotes; the head SHA tag is immutable and is what PR
43+
# deploys use, so each push changes the pod spec and forces a rollout.
44+
tags: |
45+
${{ github.event.number }}
46+
${{ github.event.pull_request.head.sha }}
4247
tag_fallback: latest
4348
triggers: ('${{ matrix.package }}/', 'common/', '.github/workflows/')
4449
build_args: |
@@ -51,6 +56,7 @@ jobs:
5156
secrets: inherit
5257
with:
5358
target: ${{ needs.init.outputs.zone }}
59+
tag: ${{ github.event.pull_request.head.sha }}
5460
triggers: ('backend/', 'frontend/', 'common/', '.github/workflows/')
5561

5662
tests:

backend/openshift.deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ parameters:
1313
- name: IMAGE_TAG
1414
description: Image tag to use
1515
required: true
16+
# PR deploys pass the immutable head SHA as IMAGE_TAG, so every push changes
17+
# the pod spec and forces a rollout (the mutable PR-number tag would leave
18+
# `oc apply` seeing an unchanged Deployment and keep serving the stale image
19+
# despite imagePullPolicy: Always). Test deploys (merge.yml) use the
20+
# PR-number tag, which is unique per merge, so the spec changes there too.
1621
- name: REGISTRY
1722
description: Container registry to import from
1823
value: ghcr.io

frontend/openshift.deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ parameters:
1313
- name: IMAGE_TAG
1414
description: Image tag to use
1515
required: true
16+
# PR deploys pass the immutable head SHA as IMAGE_TAG, so every push changes
17+
# the pod spec and forces a rollout (the mutable PR-number tag would leave
18+
# `oc apply` seeing an unchanged Deployment and keep serving the stale image
19+
# despite imagePullPolicy: Always). Test deploys (merge.yml) use the
20+
# PR-number tag, which is unique per merge, so the spec changes there too.
1621
- name: REGISTRY
1722
description: Container registry to import from
1823
value: ghcr.io

0 commit comments

Comments
 (0)