Skip to content

Commit f923b14

Browse files
committed
Only write images to cache from the Build job
Problem: There are multiples workflows and jobs all writing to the same cache causing it to be invalidated Solution: Write to cache only in the Build job and read the cache from all the other jobs.
1 parent ea306c6 commit f923b14

File tree

3 files changed

+99
-96
lines changed

3 files changed

+99
-96
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Continuous Integration
1+
name: CI
22

33
on:
44
push:
@@ -26,6 +26,7 @@ jobs:
2626
runs-on: ubuntu-22.04
2727
outputs:
2828
go_path: ${{ steps.vars.outputs.go_path }}
29+
min_k8s_version: ${{ steps.vars.outputs.min_k8s_version }}
2930
steps:
3031
- name: Checkout Repository
3132
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
@@ -37,7 +38,9 @@ jobs:
3738

3839
- name: Output Variables
3940
id: vars
40-
run: echo "go_path=$(go env GOPATH)" >> $GITHUB_OUTPUT
41+
run: |
42+
echo "go_path=$(go env GOPATH)" >> $GITHUB_OUTPUT
43+
echo "min_k8s_version=1.23.17" >> $GITHUB_OUTPUT
4144
4245
- name: Check if go.mod and go.sum are up to date
4346
run: go mod tidy && git diff --exit-code -- go.mod go.sum
@@ -160,10 +163,61 @@ jobs:
160163
path: ${{ github.workspace }}/dist
161164
key: nginx-gateway-fabric-${{ github.run_id }}-${{ github.run_number }}
162165

166+
build:
167+
name: Build Image
168+
needs: [vars, binary]
169+
strategy:
170+
fail-fast: false
171+
matrix:
172+
image: [ngf, nginx, plus]
173+
platforms: ["linux/arm64, linux/amd64"]
174+
uses: ./.github/workflows/build.yml
175+
with:
176+
image: ${{ matrix.image }}
177+
platforms: ${{ matrix.platforms }}
178+
permissions:
179+
contents: read # for docker/build-push-action to read repo content
180+
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
181+
packages: write # for docker/build-push-action to push to GHCR
182+
id-token: write # for docker/login to login to NGINX registry
183+
secrets: inherit
184+
185+
functional-tests:
186+
name: Functional tests
187+
needs: [vars, build]
188+
strategy:
189+
fail-fast: false
190+
matrix:
191+
image: [nginx, plus]
192+
k8s-version: ["${{ needs.vars.outputs.min_k8s_version }}", "latest"]
193+
uses: ./.github/workflows/functional.yml
194+
with:
195+
image: ${{ matrix.image }}
196+
k8s-version: ${{ matrix.k8s-version }}
197+
permissions:
198+
contents: read
199+
200+
conformance-tests:
201+
name: Conformance tests
202+
needs: [vars, build]
203+
strategy:
204+
fail-fast: false
205+
matrix:
206+
image: [nginx, plus]
207+
k8s-version: ["${{ needs.vars.outputs.min_k8s_version }}", "latest"]
208+
enable-experimental: [true, false]
209+
uses: ./.github/workflows/conformance.yml
210+
with:
211+
image: ${{ matrix.image }}
212+
k8s-version: ${{ matrix.k8s-version }}
213+
enable-experimental: ${{ matrix.enable-experimental }}
214+
permissions:
215+
contents: write
216+
163217
helm-tests:
164218
name: Helm Tests
165219
runs-on: ubuntu-22.04
166-
needs: [vars, binary]
220+
needs: [vars, build]
167221
steps:
168222
- name: Checkout Repository
169223
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
@@ -210,7 +264,6 @@ jobs:
210264
target: goreleaser
211265
load: true
212266
cache-from: type=gha,scope=ngf
213-
cache-to: type=gha,scope=ngf,mode=max
214267
pull: true
215268

216269
- name: Build NGINX Docker Image
@@ -221,7 +274,6 @@ jobs:
221274
context: "."
222275
load: true
223276
cache-from: type=gha,scope=nginx
224-
cache-to: type=gha,scope=nginx,mode=max
225277
pull: true
226278
build-args: |
227279
NJS_DIR=internal/mode/static/nginx/modules/src
@@ -254,25 +306,6 @@ jobs:
254306
-n nginx-gateway
255307
working-directory: ${{ github.workspace }}/deploy/helm-chart
256308

257-
build:
258-
name: Build Image
259-
needs: [vars, binary]
260-
strategy:
261-
fail-fast: false
262-
matrix:
263-
image: [ngf, nginx, plus]
264-
platforms: ["linux/arm64, linux/amd64"]
265-
uses: ./.github/workflows/build.yml
266-
with:
267-
image: ${{ matrix.image }}
268-
platforms: ${{ matrix.platforms }}
269-
permissions:
270-
contents: read # for docker/build-push-action to read repo content
271-
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
272-
packages: write # for docker/build-push-action to push to GHCR
273-
id-token: write # for docker/login to login to NGINX registry
274-
secrets: inherit
275-
276309
publish-helm:
277310
name: Package and Publish Helm Chart
278311
runs-on: ubuntu-22.04

.github/workflows/conformance.yml

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,40 @@
11
name: Conformance Testing
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- release-*
8-
tags:
9-
- "v[0-9]+.[0-9]+.[0-9]+*"
10-
pull_request:
11-
schedule:
12-
- cron: "0 4 * * *" # run every day at 4am UTC
4+
workflow_call:
5+
inputs:
6+
image:
7+
required: true
8+
type: string
9+
k8s-version:
10+
required: true
11+
type: string
12+
enable-experimental:
13+
required: true
14+
type: boolean
1315

1416
defaults:
1517
run:
1618
shell: bash
1719

18-
concurrency:
19-
group: ${{ github.ref_name }}-conformance
20-
cancel-in-progress: true
21-
2220
permissions:
2321
contents: read
2422

2523
jobs:
2624
conformance-tests:
27-
name: Gateway Conformance Tests
25+
name: Run Tests
2826
runs-on: ubuntu-22.04
29-
strategy:
30-
matrix:
31-
k8s-version: ["1.23.17", "latest"]
32-
nginx-image: [nginx, nginx-plus]
33-
enable-experimental: [true, false]
3427
permissions:
3528
contents: write # needed for uploading release artifacts
3629
steps:
3730
- name: Checkout Repository
3831
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
3932

40-
- name: Setup Golang Environment
41-
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
33+
- name: Fetch Cached Artifacts
34+
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
4235
with:
43-
go-version: stable
44-
45-
- name: Set GOPATH
46-
run: echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
36+
path: ${{ github.workspace }}/dist
37+
key: nginx-gateway-fabric-${{ github.run_id }}-${{ github.run_number }}
4738

4839
- name: Docker Buildx
4940
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0
@@ -65,7 +56,7 @@ jobs:
6556
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
6657
with:
6758
images: |
68-
name=ghcr.io/nginxinc/nginx-gateway-fabric/${{ matrix.nginx-image }}
59+
name=ghcr.io/nginxinc/nginx-gateway-fabric/${{ inputs.image == 'plus' && 'nginx-plus' || inputs.image }}
6960
tags: |
7061
type=semver,pattern={{version}}
7162
type=edge
@@ -76,18 +67,9 @@ jobs:
7667
run: |
7768
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
7869
ngf_tag=${{ steps.ngf-meta.outputs.version }}
79-
make update-ngf-manifest${{ matrix.nginx-image == 'nginx-plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
70+
make update-ngf-manifest${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
8071
working-directory: ./conformance
8172

82-
- name: Build binary
83-
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
84-
with:
85-
version: latest
86-
args: build --snapshot --clean
87-
env:
88-
TELEMETRY_ENDPOINT: "" # disables sending telemetry
89-
TELEMETRY_ENDPOINT_INSECURE: "false"
90-
9173
- name: Build NGF Docker Image
9274
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
9375
with:
@@ -97,18 +79,16 @@ jobs:
9779
target: goreleaser
9880
load: true
9981
cache-from: type=gha,scope=ngf
100-
cache-to: type=gha,scope=ngf,mode=max
10182
pull: true
10283

10384
- name: Build NGINX Docker Image
10485
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
10586
with:
106-
file: build/Dockerfile${{ matrix.nginx-image == 'nginx' && '.nginx' || '' }}${{ matrix.nginx-image == 'nginx-plus' && '.nginxplus' || ''}}
87+
file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'plus' && '.nginxplus' || ''}}
10788
tags: ${{ steps.nginx-meta.outputs.tags }}
10889
context: "."
10990
load: true
110-
cache-from: type=gha,scope=${{ matrix.nginx-image }}
111-
cache-to: type=gha,scope=${{ matrix.nginx-image }},mode=max
91+
cache-from: type=gha,scope=${{ inputs.image }}
11292
pull: true
11393
build-args: |
11494
NJS_DIR=internal/mode/static/nginx/modules/src
@@ -134,8 +114,8 @@ jobs:
134114
- name: Deploy Kubernetes
135115
id: k8s
136116
run: |
137-
k8s_version=${{ matrix.k8s-version }}
138-
make create-kind-cluster KIND_KUBE_CONFIG=${{ github.workspace }}/kube-${{ github.run_id }} ${{ ! contains(matrix.k8s-version, 'latest') && 'KIND_IMAGE=kindest/node:v${k8s_version}' || '' }}
117+
k8s_version=${{ inputs.k8s-version }}
118+
make create-kind-cluster KIND_KUBE_CONFIG=${{ github.workspace }}/kube-${{ github.run_id }} ${{ ! contains(inputs.k8s-version, 'latest') && 'KIND_IMAGE=kindest/node:v${k8s_version}' || '' }}
139119
echo "KUBECONFIG=${{ github.workspace }}/kube-${{ github.run_id }}" >> "$GITHUB_ENV"
140120
working-directory: ./conformance
141121

@@ -151,9 +131,9 @@ jobs:
151131
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
152132
ngf_tag=${{ steps.ngf-meta.outputs.version }}
153133
if [ ${{ github.event_name }} == "schedule" ]; then export GW_API_VERSION=main; fi
154-
if [ ${{ startsWith(matrix.k8s-version, '1.23') || startsWith(matrix.k8s-version, '1.24') }} == "true" ]; then export INSTALL_WEBHOOK=true; fi
155-
if [ ${{ matrix.enable-experimental }} == "true" ]; then export ENABLE_EXPERIMENTAL=true; fi
156-
make install-ngf-local-no-build${{ matrix.nginx-image == 'nginx-plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
134+
if [ ${{ startsWith(inputs.k8s-version, '1.23') || startsWith(inputs.k8s-version, '1.24') }} == "true" ]; then export INSTALL_WEBHOOK=true; fi
135+
if [ ${{ inputs.enable-experimental }} == "true" ]; then export ENABLE_EXPERIMENTAL=true; fi
136+
make install-ngf-local-no-build${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
157137
working-directory: ./conformance
158138

159139
- name: Run conformance tests
@@ -165,7 +145,7 @@ jobs:
165145
working-directory: ./conformance
166146

167147
- name: Upload profile to release
168-
if: ${{ matrix.k8s-version == 'latest' && startsWith(github.ref, 'refs/tags/') }}
148+
if: ${{ inputs.k8s-version == 'latest' && startsWith(github.ref, 'refs/tags/') }}
169149
env:
170150
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
171151
run: gh release upload ${{ github.ref_name }} conformance-profile.yaml

.github/workflows/functional.yml

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
name: Functional Testing
22

33
on:
4-
push:
5-
branches:
6-
- main
7-
- release-*
8-
tags:
9-
- "v[0-9]+.[0-9]+.[0-9]+*"
10-
pull_request:
4+
workflow_call:
5+
inputs:
6+
image:
7+
required: true
8+
type: string
9+
k8s-version:
10+
required: true
11+
type: string
1112

1213
defaults:
1314
run:
1415
shell: bash
1516

16-
concurrency:
17-
group: ${{ github.ref_name }}-functional
18-
cancel-in-progress: true
19-
2017
permissions:
2118
contents: read
2219

2320
jobs:
2421
functional-tests:
25-
name: Gateway Functional Tests
22+
name: Run Tests
2623
runs-on: ubuntu-22.04
27-
strategy:
28-
matrix:
29-
k8s-version: ["1.23.17", "latest"]
30-
nginx-image: [nginx, nginx-plus]
3124
steps:
3225
- name: Checkout Repository
3326
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
@@ -43,7 +36,6 @@ jobs:
4336
- name: Docker Buildx
4437
uses: docker/setup-buildx-action@2b51285047da1547ffb1b2203d8be4c0af6b1f20 # v3.2.0
4538

46-
4739
- name: NGF Docker meta
4840
id: ngf-meta
4941
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
@@ -61,7 +53,7 @@ jobs:
6153
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
6254
with:
6355
images: |
64-
name=ghcr.io/nginxinc/nginx-gateway-fabric/${{ matrix.nginx-image }}
56+
name=ghcr.io/nginxinc/nginx-gateway-fabric/${{ inputs.image == 'plus' && 'nginx-plus' || inputs.image }}
6557
tags: |
6658
type=semver,pattern={{version}}
6759
type=edge
@@ -85,19 +77,17 @@ jobs:
8577
context: "."
8678
load: true
8779
cache-from: type=gha,scope=ngf
88-
cache-to: type=gha,scope=ngf,mode=max
8980
pull: true
9081
target: goreleaser
9182

9283
- name: Build NGINX Docker Image
9384
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
9485
with:
95-
file: build/Dockerfile${{ matrix.nginx-image == 'nginx' && '.nginx' || '' }}${{ matrix.nginx-image == 'nginx-plus' && '.nginxplus' || ''}}
86+
file: build/Dockerfile${{ inputs.image == 'nginx' && '.nginx' || '' }}${{ inputs.image == 'plus' && '.nginxplus' || ''}}
9687
tags: ${{ steps.nginx-meta.outputs.tags }}
9788
context: "."
9889
load: true
99-
cache-from: type=gha,scope=${{ matrix.nginx-image }}
100-
cache-to: type=gha,scope=${{ matrix.nginx-image }},mode=max
90+
cache-from: type=gha,scope=${{ inputs.image }}
10191
pull: true
10292
build-args: |
10393
NJS_DIR=internal/mode/static/nginx/modules/src
@@ -107,21 +97,21 @@ jobs:
10797
- name: Deploy Kubernetes
10898
id: k8s
10999
run: |
110-
k8s_version=${{ matrix.k8s-version }}
111-
make create-kind-cluster KIND_KUBE_CONFIG=${{ github.workspace }}/kube-${{ github.run_id }} ${{ ! contains(matrix.k8s-version, 'latest') && 'KIND_IMAGE=kindest/node:v${k8s_version}' || '' }}
100+
k8s_version=${{ inputs.k8s-version }}
101+
make create-kind-cluster KIND_KUBE_CONFIG=${{ github.workspace }}/kube-${{ github.run_id }} ${{ ! contains(inputs.k8s-version, 'latest') && 'KIND_IMAGE=kindest/node:v${k8s_version}' || '' }}
112102
echo "KUBECONFIG=${{ github.workspace }}/kube-${{ github.run_id }}" >> "$GITHUB_ENV"
113103
114104
- name: Setup functional tests
115105
id: setup
116106
run: |
117107
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
118108
ngf_tag=${{ steps.ngf-meta.outputs.version }}
119-
make load-images${{ matrix.nginx-image == 'nginx-plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
109+
make load-images${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag}
120110
working-directory: ./tests
121111

122112
- name: Run functional telemetry tests
123113
run: |
124114
ngf_prefix=ghcr.io/nginxinc/nginx-gateway-fabric
125115
ngf_tag=${{ steps.ngf-meta.outputs.version }}
126-
make test${{ matrix.nginx-image == 'nginx-plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag} GINKGO_LABEL=telemetry
116+
make test${{ inputs.image == 'plus' && '-with-plus' || ''}} PREFIX=${ngf_prefix} TAG=${ngf_tag} GINKGO_LABEL=telemetry
127117
working-directory: ./tests

0 commit comments

Comments
 (0)