@@ -139,13 +139,29 @@ instance_id=$(aws ec2 run-instances \
139139 --tag-specifications ' ResourceType=instance,Tags=[{Key=Name,Value=' $platform -check-update-security' }]' |
140140 jq -r ' .Instances[0].InstanceId' )
141141
142+ # Read pinned major version for AL2023 GPU filtering
143+ pinned_major=" "
144+ if [ " $platform " = " al2023_gpu" ]; then
145+ pinned_major=$( sed -n ' /variable "nvidia_driver_major_al2023" {/,/}/p' variables.pkr.hcl | grep " default" | awk -F ' "' ' { print $2 }' )
146+ if [ -z " $pinned_major " ]; then
147+ echo " ERROR: Could not read nvidia_driver_major_al2023 from variables.pkr.hcl"
148+ exit 1
149+ fi
150+ fi
151+
142152# check-update based on platform
143153if [[ $platform == al2023* ]]; then
144154 check_upgrade_options=" --sec-severity Critical --exclude=$EXCLUDE_SEC_UPDATES_PKGS "
145155 if [[ $platform == * gpu ]]; then
146- check_upgrade_options=" nvidia-driver-cuda"
156+ # dnf check-upgrade only reports the single latest version across all majors,
157+ # so it can't detect updates within a pinned major. Instead, query the installed
158+ # version and the latest available within the pinned major, then compare locally.
159+ gpu_cmd_installed=" dnf repoquery --installed --arch=x86_64 --queryformat '%{version}' nvidia-driver-cuda"
160+ gpu_cmd_latest=" dnf repoquery --disableplugin=versionlock --arch=x86_64 --queryformat '%{version}' nvidia-driver-cuda | grep '^${pinned_major} [.]' | sort -V | tail -1"
161+ command_params=" commands=[\" echo INSTALLED=\$ (${gpu_cmd_installed} )\" ,\" echo LATEST=\$ (${gpu_cmd_latest} )\" ]"
162+ else
163+ command_params=" commands=[\" dnf --refresh check-upgrade --releasever=latest --disableplugin=versionlock $check_upgrade_options -q\" ]"
147164 fi
148- command_params=" commands=[\" dnf --refresh check-upgrade --releasever=latest --disableplugin=versionlock $check_upgrade_options -q\" ]"
149165elif [ " $platform " = " al2_gpu" ]; then
150166 # The amzn2-nvidia repository does not provide updateinfo metadata (updateinfo.xml),
151167 # which YUM relies on to classify updates as security-related. The --security flag
@@ -229,6 +245,55 @@ std_output=$(echo "$cmd_output" | jq -r '.StandardOutputContent')
229245# Delete the instance
230246terminate_out=$( aws ec2 terminate-instances --instance-ids $instance_id )
231247
248+ # AL2023 GPU uses repoquery instead of check-upgrade, handle separately
249+ if [ " $platform " = " al2023_gpu" ]; then
250+ if [ " $cmd_response_code " -ne " $SUCCESS_CODE " ]; then
251+ echo " Unknown issue with the command execution"
252+ exit 1
253+ fi
254+
255+ installed_version=$( echo " $std_output " | grep " ^INSTALLED=" | cut -d' =' -f2)
256+ latest_repo_version=$( echo " $std_output " | grep " ^LATEST=" | cut -d' =' -f2)
257+
258+ if [ -z " $installed_version " ] || [ -z " $latest_repo_version " ]; then
259+ echo " ERROR: Could not determine installed or latest NVIDIA driver version"
260+ exit 1
261+ fi
262+
263+ # Compare installed vs latest within pinned major
264+ newer=$( printf ' %s\n%s' " $installed_version " " $latest_repo_version " | sort -V | tail -1)
265+ if [ " $newer " = " $installed_version " ]; then
266+ echo " false"
267+ exit 0
268+ fi
269+
270+ # The AMI build installs min(repo, S3 GRID .run), so check the GRID bucket
271+ # to determine the actual version that would be installed.
272+ grid_driver_version=$( aws s3 ls --recursive s3://ec2-linux-nvidia-drivers/ --no-sign-request |
273+ grep -Eo " (NVIDIA-Linux-x86_64-)[0-9]+\.[0-9]+\.[0-9]+(-grid-aws\.run)" |
274+ cut -d' -' -f4 |
275+ grep " ^${pinned_major} \." |
276+ sort -V |
277+ tail -1)
278+ if [ -z " $grid_driver_version " ]; then
279+ echo " ERROR: Could not determine NVIDIA GRID driver version from S3 for major ${pinned_major} "
280+ exit 1
281+ fi
282+
283+ # Use min(repo, GRID) as the effective version, same as the install script
284+ effective_version=$( printf ' %s\n%s' " $latest_repo_version " " $grid_driver_version " | sort -V | head -1)
285+
286+ # Only trigger a release if the effective version is newer than installed
287+ newer=$( printf ' %s\n%s' " $installed_version " " $effective_version " | sort -V | tail -1)
288+ if [ " $newer " = " $installed_version " ]; then
289+ echo " false"
290+ exit 0
291+ fi
292+
293+ echo " true $effective_version "
294+ exit 0
295+ fi
296+
232297# Return whether update is necessary
233298if [ " $cmd_response_code " -eq " $UPDATE_EXISTS_CODE " ]; then
234299 if [ " $platform " = " al2_gpu" ]; then
@@ -259,20 +324,9 @@ if [ "$cmd_response_code" -eq "$UPDATE_EXISTS_CODE" ]; then
259324 ;;
260325 esac
261326 elif [ " $platform " = " al2023_gpu" ]; then
262- nvidia_driver_version=$( echo " $std_output " | grep " nvidia-driver-cuda" | awk ' {print $2}' | cut -d' -' -f1 | sed ' s/^[0-9]://' )
263- # The AMI build pins to min(repo, S3 GRID .run) so all three driver
264- # variants can be built at the same version. Mirror that logic here.
265- grid_driver_version=$( aws s3 ls --recursive s3://ec2-linux-nvidia-drivers/ --no-sign-request |
266- grep -Eo " (NVIDIA-Linux-x86_64-)[0-9]+\.[0-9]+\.[0-9]+(-grid-aws\.run)" |
267- cut -d' -' -f4 |
268- sort -V |
269- tail -1)
270- if [ -z " $grid_driver_version " ]; then
271- echo " ERROR: Could not determine NVIDIA GRID driver version from S3"
272- exit 1
273- fi
274- nvidia_driver_version=$( printf ' %s\n%s\n' " $nvidia_driver_version " " $grid_driver_version " | sort -V | head -1)
275- echo " true $nvidia_driver_version "
327+ # This path should not be reached; al2023_gpu is handled above via repoquery
328+ echo " ERROR: Unexpected al2023_gpu in check-upgrade result path"
329+ exit 1
276330 else
277331 echo " true"
278332 fi
0 commit comments