Skip to content

Commit 0fc5b6e

Browse files
authored
add build_tag variables (nginx#5316)
1 parent ec022da commit 0fc5b6e

File tree

2 files changed

+73
-22
lines changed

2 files changed

+73
-22
lines changed

.github/scripts/variables.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,50 @@ if [ "$PWD" != "$ROOTDIR" ]; then
1212
cd "$ROOTDIR";
1313
fi
1414

15+
get_docker_md5() {
16+
docker_md5=$(find build .github/data/version.txt -type f ! -name "*.md" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
17+
echo "${docker_md5:0:8}"
18+
}
19+
20+
get_go_code_md5() {
21+
find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" -o -name "version.txt" \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }'
22+
}
23+
24+
get_tests_md5() {
25+
find tests perf-tests .github/data/version.txt -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }'
26+
}
27+
28+
get_chart_md5() {
29+
find charts .github/data/version.txt -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }'
30+
}
31+
32+
get_actions_md5() {
33+
find .github .github/data/version.txt -type f -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }'
34+
}
35+
36+
get_build_tag() {
37+
echo "$(get_docker_md5) $(get_go_code_md5)" | md5sum | awk '{ print $1 }'
38+
}
39+
40+
get_stable_tag() {
41+
echo "$(get_build_tag) $(get_tests_md5) $(get_chart_md5) $(get_actions_md5)" | md5sum | awk '{ print $1 }'
42+
}
43+
1544
case $INPUT in
1645
docker_md5)
17-
docker_md5=$(find . -type f \( -name "Dockerfile" -o -name version.txt \) -not -path "./tests*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')
18-
echo "docker_md5=${docker_md5:0:8}"
46+
echo "docker_md5=$(get_docker_md5)"
1947
;;
2048

2149
go_code_md5)
22-
echo "go_code_md5=$(find . -type f \( -name "*.go" -o -name go.mod -o -name go.sum -o -name "*.tmpl" \) -not -path "./docs*" -exec md5sum {} + | LC_ALL=C sort | md5sum | awk '{ print $1 }')"
50+
echo "go_code_md5=$(get_go_code_md5)"
51+
;;
52+
53+
build_tag)
54+
echo "build_tag=$(get_build_tag)"
55+
;;
56+
57+
stable_tag)
58+
echo "stable_tag=$(get_stable_tag)"
2359
;;
2460

2561
*)

.github/workflows/ci.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
ic_version: ${{ steps.vars.outputs.ic_version }}
4747
publish_images: ${{ steps.vars.outputs.publish }}
4848
docker_md5: ${{ steps.vars.outputs.docker_md5 }}
49+
build_tag: ${{ steps.vars.outputs.build_tag }}
50+
stable_tag: ${{ steps.vars.outputs.stable_tag }}
4951
forked_workflow: ${{ (github.event.pull_request.head.repo.full_name != github.repository) && ! (startsWith(github.ref, 'refs/heads/release-') || github.ref_name == 'main') }}
5052
steps:
5153
- name: Checkout Repository
@@ -96,6 +98,8 @@ jobs:
9698
echo "publish=$publish" >> $GITHUB_OUTPUT
9799
./.github/scripts/variables.sh go_code_md5 >> $GITHUB_OUTPUT
98100
./.github/scripts/variables.sh docker_md5 >> $GITHUB_OUTPUT
101+
./.github/scripts/variables.sh build_tag >> $GITHUB_OUTPUT
102+
./.github/scripts/variables.sh stable_tag >> $GITHUB_OUTPUT
99103
cat $GITHUB_OUTPUT
100104
101105
- name: Fetch Cached Binary Artifacts
@@ -235,16 +239,20 @@ jobs:
235239
if: ${{ needs.checks.outputs.binary_cache_hit != 'true' }}
236240

237241
helm-tests:
238-
name: Helm Tests
242+
name: Helm Tests ${{ matrix.base-os }}
239243
runs-on: ubuntu-22.04
240244
needs: [checks, binaries]
241245
strategy:
242246
matrix:
243247
include:
244-
- image: debian
248+
- base-os: debian
249+
image: gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic/nginx-ingress
250+
tag: ${{ needs.checks.outputs.build_tag }}
245251
type: oss
246252
platforms: "linux/arm, linux/arm64, linux/amd64, linux/ppc64le, linux/s390x"
247-
- image: debian-plus
253+
- base-os: debian-plus
254+
image: gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic/nginx-plus-ingress
255+
tag: ${{ needs.checks.outputs.build_tag }}
248256
type: plus
249257
platforms: "linux/arm64, linux/amd64"
250258
permissions:
@@ -289,7 +297,7 @@ jobs:
289297
- name: Check if base images exist
290298
id: base_exists
291299
run: |
292-
if docker manifest inspect gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic-base/${{ matrix.type }}:${{ needs.checks.outputs.docker_md5 }}-${{ matrix.image }}; then
300+
if docker manifest inspect gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic-base/${{ matrix.type }}:${{ needs.checks.outputs.docker_md5 }}-${{ matrix.base-os }}; then
293301
echo "exists=0" >> $GITHUB_OUTPUT
294302
else
295303
echo "exists=1" >> $GITHUB_OUTPUT
@@ -301,34 +309,34 @@ jobs:
301309
with:
302310
file: build/Dockerfile
303311
context: "."
304-
cache-from: type=gha,scope=${{ matrix.image }}
305-
cache-to: type=gha,scope=${{ matrix.image }},mode=max
312+
cache-from: type=gha,scope=${{ matrix.base-os }}
313+
cache-to: type=gha,scope=${{ matrix.base-os }},mode=max
306314
target: common
307-
tags: gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic-base/${{ matrix.type }}:${{ needs.checks.outputs.docker_md5 }}-${{ matrix.image }}
315+
tags: gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic-base/${{ matrix.type }}:${{ needs.checks.outputs.docker_md5 }}-${{ matrix.base-os }}
308316
platforms: ${{ matrix.platforms }}
309317
pull: true
310318
push: true
311319
build-args: |
312-
BUILD_OS=${{ matrix.image }}
320+
BUILD_OS=${{ matrix.base-os }}
313321
IC_VERSION=${{ needs.checks.outputs.ic_version }}
314322
secrets: |
315323
${{ matrix.type == 'plus' && format('"nginx-repo.crt={0}"', secrets.NGINX_CRT) || '' }}
316324
${{ matrix.type == 'plus' && format('"nginx-repo.key={0}"', secrets.NGINX_KEY) || '' }}
317325
if: ${{ needs.checks.outputs.forked_workflow == 'false' && steps.base_exists.outputs.exists != 0 }}
318326

319-
- name: Build Docker Image ${{ matrix.image }}
327+
- name: Build Docker Image ${{ matrix.base-os }}
320328
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
321329
with:
322330
file: build/Dockerfile
323331
context: "."
324-
cache-from: type=gha,scope=${{ matrix.image }}
332+
cache-from: type=gha,scope=${{ matrix.base-os }}
325333
target: goreleaser${{ needs.checks.outputs.forked_workflow == 'false' && '-prebuilt' || '' }}
326-
tags: ${{ matrix.type }}:${{ github.sha }}
334+
tags: "${{ matrix.image }}:${{ matrix.tag }}"
327335
pull: true
328336
load: true
329337
build-args: |
330-
BUILD_OS=${{ matrix.image }}
331-
PREBUILT_BASE_IMG=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic-base/${{ matrix.type }}:${{ needs.checks.outputs.docker_md5 }}-${{ matrix.image }}
338+
BUILD_OS=${{ matrix.base-os }}
339+
PREBUILT_BASE_IMG=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic-base/${{ matrix.type }}:${{ needs.checks.outputs.docker_md5 }}-${{ matrix.base-os }}
332340
IC_VERSION=CI
333341
secrets: |
334342
${{ matrix.type == 'plus' && format('"nginx-repo.crt={0}"', secrets.NGINX_CRT) || '' }}
@@ -338,15 +346,15 @@ jobs:
338346
id: k8s
339347
run: |
340348
kind create cluster --name ${{ github.run_id }} --image=kindest/node:v${{ needs.checks.outputs.k8s_latest }} --wait 75s
341-
kind load docker-image ${{ matrix.type }}:${{ github.sha }} --name ${{ github.run_id }}
349+
kind load docker-image ${{ matrix.image }}:${{ matrix.tag }} --name ${{ github.run_id }}
342350
343351
- name: Install Chart
344352
run: >
345353
helm install
346354
${{ matrix.type }}
347355
.
348-
--set controller.image.repository=${{ matrix.type }}
349-
--set controller.image.tag=${{ github.sha }}
356+
--set controller.image.repository=${{ matrix.image }}
357+
--set controller.image.tag=${{ matrix.tag }}
350358
--set controller.service.type=NodePort
351359
--set controller.nginxplus=${{ contains(matrix.type, 'plus') && 'true' || 'false' }}
352360
--wait
@@ -453,6 +461,13 @@ jobs:
453461
- name: Checkout Repository
454462
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
455463

464+
- name: Set image variables
465+
id: image_details
466+
run: |
467+
echo "name=gcr.io/f5-gcs-7899-ptg-ingrss-ctlr/dev/nginx-ic${{ contains(matrix.images.nap_modules, 'dos') && '-dos' || '' }}${{ contains(matrix.images.nap_modules, 'waf') && '-nap' || '' }}/nginx${{ contains(matrix.images.image, 'plus') && '-plus' || '' }}-ingress" >> $GITHUB_OUTPUT
468+
echo "build_tag=${{ needs.checks.outputs.build_tag }}${{ contains(matrix.images.image, 'ubi') && '-ubi' || '' }}${{ contains(matrix.images.image, 'alpine') && '-alpine' || '' }}${{ contains(matrix.images.target, 'aws') && '-mktpl' || '' }}${{ contains(matrix.images.image, 'fips') && '-fips' || ''}}" >> $GITHUB_OUTPUT
469+
echo "stable_tag=${{ needs.checks.outputs.stable_tag }}${{ contains(matrix.images.image, 'ubi') && '-ubi' || '' }}${{ contains(matrix.images.image, 'alpine') && '-alpine' || '' }}${{ contains(matrix.images.target, 'aws') && '-mktpl' || '' }}${{ contains(matrix.images.image, 'fips') && '-fips' || ''}}" >> $GITHUB_OUTPUT
470+
456471
- name: NAP modules
457472
id: nap_modules
458473
run: |
@@ -553,7 +568,7 @@ jobs:
553568
cache-from: type=gha,scope=${{ matrix.images.image }}${{ steps.nap_modules.outputs.name != '' && format('-{0}', steps.nap_modules.outputs.name) || '' }}
554569
cache-to: type=gha,scope=${{ matrix.images.image }}${{ steps.nap_modules.outputs.name != '' && format('-{0}', steps.nap_modules.outputs.name) || '' }},mode=max
555570
target: goreleaser${{ needs.checks.outputs.forked_workflow == 'false' && '-prebuilt' || '' }}
556-
tags: "docker.io/nginx/nginx${{ contains(matrix.images.image, 'plus') && '-plus' || '' }}-ingress:${{ matrix.images.image }}${{ contains(matrix.images.marker, 'dos') && '-dos' || '' }}${{ contains(matrix.images.marker, 'appprotect') && '-nap' || '' }}-${{ github.sha }}"
571+
tags: "${{ steps.image_details.outputs.name }}:${{ steps.image_details.outputs.build_tag }}"
557572
load: true
558573
pull: true
559574
build-args: |
@@ -572,8 +587,8 @@ jobs:
572587
uses: ./.github/actions/smoke-tests
573588
with:
574589
image-type: ${{ matrix.images.image }}
575-
image-name: docker.io/nginx/nginx${{ contains(matrix.images.image, 'plus') && '-plus' || '' }}-ingress
576-
tag: ${{ matrix.images.image }}${{ contains(matrix.images.marker, 'dos') && '-dos' || '' }}${{ contains(matrix.images.marker, 'appprotect') && '-nap' || '' }}-${{ github.sha }}
590+
image-name: ${{ steps.image_details.outputs.name }}
591+
tag: ${{ steps.image_details.outputs.build_tag }}
577592
marker: ${{ matrix.images.marker != '' && matrix.images.marker || '' }}
578593
k8s-version: ${{ matrix.k8s }}
579594
azure-ad-secret: ${{ secrets.AZURE_AD_AUTOMATION }}

0 commit comments

Comments
 (0)