Skip to content

Commit 7d51350

Browse files
ci: build e2e image once and reuse across jobs (#2948)\n\n- add shared build-e2e-image job in tests.yaml\n- e2e-tests downloads and loads artifact, avoids rebuild\n- reusable chainsaw workflow accepts artifacts_run_id and loads image\n- include build-e2e-image in final passed gate\n\nThis reduces duplicate Docker builds and speeds up CI, while keeping behavior unchanged.\n\nCo-authored-by: CI <ci@codex>
1 parent 96b9d88 commit 7d51350

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

.github/workflows/__e2e_chainsaw_tests.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
description: "Kind node image version"
99
type: string
1010
required: true
11+
artifacts_run_id:
12+
description: "Workflow run id that produced the e2e image artifact"
13+
type: string
14+
required: true
1115

1216
permissions:
1317
contents: read
@@ -32,8 +36,15 @@ jobs:
3236
egress-policy: audit
3337
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3438

35-
- name: build docker image
36-
run: make docker.build
39+
- name: download e2e image artifact
40+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
41+
with:
42+
name: kong-operator-e2e-image-${{ inputs.artifacts_run_id }}
43+
run-id: ${{ inputs.artifacts_run_id }}
44+
github-token: ${{ secrets.GITHUB_TOKEN }}
45+
46+
- name: load docker image
47+
run: docker load -i kong-operator_e2e.tar
3748

3849
- uses: jdx/mise-action@e79ddf65a11cec7b0e882bedced08d6e976efb2d # v3.6.2
3950
with:

.github/workflows/tests.yaml

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ env:
4242
MISE_VERBOSE: 1
4343

4444
jobs:
45+
build-e2e-image:
46+
runs-on: ubuntu-latest
47+
needs: [check-docs-only]
48+
if: ${{ needs.check-docs-only.outputs.docs_only != 'true' }}
49+
env:
50+
IMG: kong-operator
51+
TAG: e2e-${{ github.sha }}
52+
steps:
53+
- name: Harden Runner
54+
uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
55+
with:
56+
egress-policy: audit
57+
- name: checkout repository
58+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
59+
60+
- name: setup golang
61+
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
62+
with:
63+
go-version-file: go.mod
64+
65+
- name: build docker image
66+
run: make docker.build
67+
68+
- name: save docker image as artifact
69+
run: docker save ${{ env.IMG }}:${{ env.TAG }} -o kong-operator_e2e.tar
70+
71+
- name: upload docker image artifact
72+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
73+
with:
74+
name: kong-operator-e2e-image-${{ github.run_id }}
75+
path: kong-operator_e2e.tar
76+
retention-days: 1
77+
if-no-files-found: error
78+
4579
check-docs-only:
4680
runs-on: ubuntu-latest
4781
outputs:
@@ -774,7 +808,7 @@ jobs:
774808

775809
e2e-tests:
776810
runs-on: ubuntu-latest
777-
needs: [check-docs-only]
811+
needs: [check-docs-only, build-e2e-image]
778812
if: ${{ needs.check-docs-only.outputs.docs_only != 'true' }}
779813
steps:
780814
- name: Harden Runner
@@ -791,11 +825,13 @@ jobs:
791825
with:
792826
go-version-file: go.mod
793827

794-
- name: build docker image
795-
env:
796-
IMG: kong-operator
797-
TAG: e2e-${{ github.sha }}
798-
run: make docker.build
828+
- name: download e2e image artifact
829+
uses: actions/download-artifact@70fc10c6e5e1ce46ad2ea6f2b72d43f7d47b13c3 # v8.0.0
830+
with:
831+
name: kong-operator-e2e-image-${{ github.run_id }}
832+
833+
- name: load docker image
834+
run: docker load -i kong-operator_e2e.tar
799835

800836
- uses: jdx/mise-action@e79ddf65a11cec7b0e882bedced08d6e976efb2d # v3.6.2
801837
with:
@@ -825,12 +861,14 @@ jobs:
825861
e2e-tests-chainsaw:
826862
needs:
827863
- check-docs-only
864+
- build-e2e-image
828865
- matrix_k8s_node_versions
829866
if: ${{ needs.check-docs-only.outputs.docs_only != 'true' }}
830867
uses: ./.github/workflows/__e2e_chainsaw_tests.yaml
831868
secrets: inherit
832869
with:
833870
node_image_version: ${{ needs.matrix_k8s_node_versions.outputs.latest }}
871+
artifacts_run_id: ${{ github.run_id }}
834872

835873
buildpulse-report:
836874
needs:
@@ -885,6 +923,7 @@ jobs:
885923
- samples
886924
- install-with-kustomize
887925
- build
926+
- build-e2e-image
888927
- CRDs
889928
- unit-tests
890929
- envtest-tests

0 commit comments

Comments
 (0)