From 2d27133fcfcd44b70d2c4cb7a7ab4ed65e7d4d7d Mon Sep 17 00:00:00 2001 From: Liangsheng Yin Date: Wed, 5 Aug 2026 15:06:01 -0700 Subject: [PATCH] [CI] Skip `apt-get` when the required packages are already installed (#33757) --- scripts/ci/cuda/ci_install_dependency.sh | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/scripts/ci/cuda/ci_install_dependency.sh b/scripts/ci/cuda/ci_install_dependency.sh index 161b62fe9..b7c9bc820 100755 --- a/scripts/ci/cuda/ci_install_dependency.sh +++ b/scripts/ci/cuda/ci_install_dependency.sh @@ -134,22 +134,32 @@ cleanup_stale_shm() { } install_apt_packages() { - apt-get update || true CI_APT_PACKAGES=( python3 python3-pip python3-venv python3-dev git libnuma-dev libssl-dev pkg-config libibverbs-dev libibverbs1 ibverbs-providers ibverbs-utils ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev ) - apt-get install -y --no-install-recommends "${CI_APT_PACKAGES[@]}" || { - echo "Warning: apt-get install failed, checking if required packages are available..." - for pkg in "${CI_APT_PACKAGES[@]}"; do - if ! dpkg -l "$pkg" 2>/dev/null | grep -q "^ii"; then - echo "ERROR: Required package $pkg is not installed and apt-get failed" - exit 1 - fi - done - echo "All required packages are already installed, continuing..." - } + + # The images bake these in, so the usual run pays apt-get update's round + # trips to install nothing. Skipping it costs no currency either: apt-get + # install only ever considers the packages named above, and a passing run + # leaves 100+ others un-upgraded - the image is what pins these versions. + local pkg + local -a MISSING_APT_PACKAGES=() + for pkg in "${CI_APT_PACKAGES[@]}"; do + dpkg -l "$pkg" 2>/dev/null | grep -q "^ii" || MISSING_APT_PACKAGES+=("$pkg") + done + + if [ ${#MISSING_APT_PACKAGES[@]} -eq 0 ]; then + echo "All required apt packages are already installed, skipping apt-get" + else + echo "Installing missing apt packages: ${MISSING_APT_PACKAGES[*]}" + apt-get update || true + apt-get install -y --no-install-recommends "${MISSING_APT_PACKAGES[@]}" || { + echo "ERROR: apt-get failed to install: ${MISSING_APT_PACKAGES[*]}" + exit 1 + } + fi mark_step_done "${FUNCNAME[0]}" }