Skip to content

Commit 65f583c

Browse files
committed
allow specific precompiled images to be rebuilt
Signed-off-by: Rahul Sharma <[email protected]>
1 parent 0c6d680 commit 65f583c

4 files changed

Lines changed: 115 additions & 20 deletions

File tree

.github/workflows/precompiled.yaml

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@ on:
1919
schedule:
2020
- cron: '00 09 * * *'
2121
workflow_dispatch:
22+
inputs:
23+
driver_branch:
24+
description: 'Driver branch to build (e.g. 535). Leave empty for all.'
25+
required: false
26+
default: ''
27+
kernel_flavor:
28+
description: 'Kernel flavor to build (e.g. azure). Leave empty for all.'
29+
required: false
30+
default: ''
31+
dist:
32+
description: 'Distribution to build (e.g. ubuntu22.04). Leave empty for all.'
33+
required: false
34+
default: ''
35+
lts_kernel:
36+
description: 'LTS kernel series to build (e.g. 6.8). Leave empty for all.'
37+
required: false
38+
default: ''
39+
force_rebuild:
40+
description: 'Force rebuild and re-publish even if the image tag already exists'
41+
required: false
42+
type: boolean
43+
default: false
2244

2345
jobs:
2446
set-driver-version-matrix:
@@ -35,22 +57,38 @@ jobs:
3557
id: extract_driver_branch
3658
run: |
3759
# get driver_branch
38-
DRIVER_BRANCH=("535" "570" "580")
60+
if [ -n "${{ inputs.driver_branch }}" ]; then
61+
DRIVER_BRANCH=("${{ inputs.driver_branch }}")
62+
else
63+
DRIVER_BRANCH=("535" "570" "580")
64+
fi
3965
driver_branch_json=$(printf '%s\n' "${DRIVER_BRANCH[@]}" | jq -R . | jq -cs .)
4066
echo "driver_branch=$driver_branch_json" >> $GITHUB_OUTPUT
4167
4268
# get kernel flavors
43-
KERNEL_FLAVORS=("aws" "azure" "azure-fde" "generic" "nvidia" "oracle")
69+
if [ -n "${{ inputs.kernel_flavor }}" ]; then
70+
KERNEL_FLAVORS=("${{ inputs.kernel_flavor }}")
71+
else
72+
KERNEL_FLAVORS=("aws" "azure" "azure-fde" "generic" "nvidia" "oracle")
73+
fi
4474
kernel_flavors_json=$(printf '%s\n' "${KERNEL_FLAVORS[@]}" | jq -R . | jq -cs .)
4575
echo "kernel_flavors=$kernel_flavors_json" >> $GITHUB_OUTPUT
4676
4777
# get ubuntu distributions
48-
DIST=("ubuntu22.04" "ubuntu24.04")
78+
if [ -n "${{ inputs.dist }}" ]; then
79+
DIST=("${{ inputs.dist }}")
80+
else
81+
DIST=("ubuntu22.04" "ubuntu24.04")
82+
fi
4983
dist_json=$(printf '%s\n' "${DIST[@]}" | jq -R . | jq -cs .)
5084
echo "dist=$dist_json" >> $GITHUB_OUTPUT
5185
5286
# LTS_KERNEL setup
53-
LTS_KERNEL=("5.15" "6.8")
87+
if [ -n "${{ inputs.lts_kernel }}" ]; then
88+
LTS_KERNEL=("${{ inputs.lts_kernel }}")
89+
else
90+
LTS_KERNEL=("5.15" "6.8")
91+
fi
5492
lts_kernel_json=$(printf '%s\n' "${LTS_KERNEL[@]}" | jq -R . | jq -cs .)
5593
echo "lts_kernel=$lts_kernel_json" >> $GITHUB_OUTPUT
5694
@@ -200,6 +238,7 @@ jobs:
200238
DIST: ${{ matrix.dist }}
201239
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
202240
LTS_KERNEL: ${{ matrix.lts_kernel }}
241+
FORCE_REBUILD: ${{ inputs.force_rebuild || 'false' }}
203242
run: |
204243
kernel_flavors_json='${{ needs.set-driver-version-matrix.outputs.kernel_flavors }}'
205244
KERNEL_FLAVORS=($(echo "$kernel_flavors_json" | jq -r '.[]'))
@@ -213,7 +252,12 @@ jobs:
213252
done))
214253
fi
215254
source ./tests/scripts/ci-precompiled-helpers.sh
216-
KERNEL_VERSIONS=($(get_kernel_versions_to_test KERNEL_FLAVORS[@] DRIVER_BRANCHES[@] $DIST $LTS_KERNEL))
255+
KERNEL_VERSIONS=($(get_kernel_versions_to_test KERNEL_FLAVORS[@] DRIVER_BRANCHES[@] $DIST $LTS_KERNEL $FORCE_REBUILD))
256+
rc=$?
257+
if [[ $rc -ne 0 ]]; then
258+
echo "registry connectivity error while determining kernel versions to test" >&2
259+
exit 1
260+
fi
217261
if [ -z "$KERNEL_VERSIONS" ]; then
218262
# no new kernel release
219263
echo "Skipping e2e tests"

scripts/precompiled.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,36 @@ function pushBaseImage(){
5454
make IMAGE_NAME=${IMAGE_NAME} DRIVER_BRANCH=${DRIVER_BRANCH} KERNEL_FLAVOR=${KERNEL_FLAVOR} push-base-${BASE_TARGET}
5555
}
5656

57+
function imageDigest(){
58+
regctl image digest --list "$1" 2>/dev/null
59+
}
60+
61+
function manifestsMatch(){
62+
local src_digest
63+
local dst_digest
64+
src_digest=$(imageDigest "$1") || { echo "failed to get digest for $1 - assuming manifests differ"; return 1; }
65+
dst_digest=$(imageDigest "$2") || { echo "failed to get digest for $2 - assuming manifests differ"; return 1; }
66+
[ "$src_digest" = "$dst_digest" ]
67+
}
68+
5769
function pushImage(){
5870
# check if image exists in output registry
5971
# note: DIST is in the form "signed_<distribution>", so we drop the '*_' prefix
6072
# to extract the distribution string.
61-
local out_image=${OUT_IMAGE_NAME}:${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST##*_}
73+
local tag=${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST##*_}
74+
local out_image=${OUT_IMAGE_NAME}:${tag}
75+
local in_image=${IMAGE_NAME}:${tag}
6276
if imageExists "$out_image"; then
6377
echo "image tag already exists in output registry - $out_image"
6478
if [ "$FORCE_PUSH" != "true" ]; then
65-
echo "exiting"
66-
return 0
79+
if manifestsMatch "$in_image" "$out_image"; then
80+
echo "source and destination manifests match - skipping push"
81+
return 0
82+
fi
83+
echo "source and destination manifests differ - pushing updated image"
84+
else
85+
echo "overwriting image tag - $out_image"
6786
fi
68-
echo "overwriting image tag - $out_image"
6987
fi
7088
# push the image
7189
make DRIVER_VERSIONS=${DRIVER_VERSIONS} DRIVER_BRANCH=${DRIVER_BRANCH} push-${DIST}

tests/scripts/ci-precompiled-helpers.sh

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
get_kernel_versions_to_test() {
2-
if [[ "$#" -ne 4 ]]; then
3-
echo " Error:$0 must be called with KERNEL_FLAVORS DRIVER_BRANCHES DIST LTS_KERNEL" >&2
2+
if [[ "$#" -lt 4 ]]; then
3+
echo " Error:$0 must be called with KERNEL_FLAVORS DRIVER_BRANCHES DIST LTS_KERNEL [FORCE_REBUILD]" >&2
44
exit 1
55
fi
66

77
local -a KERNEL_FLAVORS=("${!1}")
88
local -a DRIVER_BRANCHES=("${!2}")
99
local DIST="$3"
1010
local LTS_KERNEL="$4"
11+
local FORCE_REBUILD="${5:-false}"
1112

1213
kernel_versions=()
14+
local had_errors=false
1315
for kernel_flavor in "${KERNEL_FLAVORS[@]}"; do
1416
for DRIVER_BRANCH in "${DRIVER_BRANCHES[@]}"; do
15-
source ./tests/scripts/findkernelversion.sh "${kernel_flavor}" "$DRIVER_BRANCH" "$DIST" "$LTS_KERNEL" >&2
17+
regctl_error=false
18+
source ./tests/scripts/findkernelversion.sh "${kernel_flavor}" "$DRIVER_BRANCH" "$DIST" "$LTS_KERNEL" "$FORCE_REBUILD" >&2
19+
if [[ "$regctl_error" == true ]]; then
20+
echo "skipping ${kernel_flavor}/${DRIVER_BRANCH} due to registry connectivity error" >&2
21+
had_errors=true
22+
break
23+
fi
1624
if [[ "$should_continue" == true ]]; then
1725
break
1826
fi
@@ -28,4 +36,7 @@ get_kernel_versions_to_test() {
2836
kernel_versions[$i]="${kernel_versions[$i]}-$DIST"
2937
done
3038
echo "${kernel_versions[@]}"
39+
if [[ "$had_errors" == true ]]; then
40+
return 1
41+
fi
3142
}

tests/scripts/findkernelversion.sh

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/bin/bash
22

3-
if [[ $# -ne 4 ]]; then
4-
echo " KERNEL_FLAVOR DRIVER_BRANCH DIST LTS_KERNEL are required"
3+
if [[ $# -lt 4 ]]; then
4+
echo " KERNEL_FLAVOR DRIVER_BRANCH DIST LTS_KERNEL [FORCE_REBUILD] are required"
55
exit 1
66
fi
77

88
export KERNEL_FLAVOR="${1}"
99
export DRIVER_BRANCH="${2}"
1010
export DIST="${3}"
1111
export LTS_KERNEL="${4}"
12+
FORCE_REBUILD="${5:-false}"
1213

1314
export REGCTL_VERSION=v0.7.1
1415
mkdir -p bin
@@ -32,12 +33,33 @@ if [ -n "$artifact" ]; then
3233
fi
3334

3435
# calculate driver tag
35-
status_nvcr=0
36-
status_ghcr=0
37-
regctl tag ls nvcr.io/nvidia/driver | grep "^${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST}$" || status_nvcr=$?
38-
regctl tag ls ghcr.io/nvidia/driver | grep "^${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST}$" || status_ghcr=$?
39-
if [[ $status_nvcr -eq 0 || $status_ghcr -eq 0 ]]; then
36+
nvcr_tags=$(regctl tag ls nvcr.io/nvidia/driver 2>&1)
37+
nvcr_status=$?
38+
if [[ $nvcr_status -ne 0 ]]; then
39+
echo "failed to list tags from nvcr.io/nvidia/driver (exit $nvcr_status): $nvcr_tags" >&2
4040
export should_continue=false
41-
else
41+
export regctl_error=true
42+
return 1
43+
fi
44+
45+
if echo "$nvcr_tags" | grep -q "^${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST}$"; then
46+
echo "image tag ${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST} already exists on nvcr.io - rebuild not allowed" >&2
47+
export should_continue=false
48+
elif [[ "$FORCE_REBUILD" == "true" ]]; then
49+
echo "force rebuild requested for ${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST}" >&2
4250
export should_continue=true
51+
else
52+
ghcr_tags=$(regctl tag ls ghcr.io/nvidia/driver 2>&1)
53+
ghcr_status=$?
54+
if [[ $ghcr_status -ne 0 ]]; then
55+
echo "failed to list tags from ghcr.io/nvidia/driver (exit $ghcr_status): $ghcr_tags" >&2
56+
export should_continue=false
57+
export regctl_error=true
58+
return 1
59+
fi
60+
if echo "$ghcr_tags" | grep -q "^${DRIVER_BRANCH}-${KERNEL_VERSION}-${DIST}$"; then
61+
export should_continue=false
62+
else
63+
export should_continue=true
64+
fi
4365
fi

0 commit comments

Comments
 (0)