Browse Source

Speed up execution time of yum_update.sh

Doing a yum update with an explicit list of packages where many of
those packages are already up-to-date has a significant time penalty.
This change includes version comparison to remove packages from
packages_for_update where the installed and available versions are
identical.

This change also only installs yum-plugin-priorities if it is not
already installed, for some extra time saving.

For a specific example of time saved, I had a
centos-binary-rsyslog-base with the following timings.

Without this change
-------------------
packages passed to yum update: 87
packages actually updated:     11
time taken                     35s

With this change
-------------------
packages passed to yum update: 11
packages actually updated:     11
time taken                     10s

This time saved should add up over all of the container images during
image prepare in CI.

Change-Id: Ie282acd1cdc0de8d875959ec9578122fe34f98ac
master
Steve Baker 3 months ago
parent
commit
9014df9472
1 changed files with 17 additions and 5 deletions
  1. 17
    5
      files/yum_update.sh

+ 17
- 5
files/yum_update.sh View File

@@ -4,9 +4,17 @@ set -eoux pipefail
4 4
 
5 5
 packages_for_update=
6 6
 if [ -n "$1" ] && command -v repoquery >/dev/null 2>&1; then
7
-    installed=$(rpm -qa --qf "%{NAME}\n" | sort)
8
-    available=$(repoquery --provides --disablerepo='*' --enablerepo=$1 --qf %{NAME} -a | cut -d= -f1 | sort)
9
-    packages_for_update=$(comm -12 <(printf "%s\n" $installed) <(printf "%s\n" $available))
7
+    installed_versions=$(rpm -qa --qf "%{NAME} = %{VERSION}-%{RELEASE}\n" | sort)
8
+    available_versions=$(repoquery --provides --disablerepo='*' --enablerepo=$1 -a | sort)
9
+    uptodate_versions=$(comm -12 <(printf "%s\n" "$installed_versions") <(printf "%s\n" "$available_versions"))
10
+
11
+
12
+    installed=$(printf "%s\n" "$installed_versions" | cut -d= -f1 | sort)
13
+    available=$(printf "%s\n" "$available_versions" | cut -d= -f1 | sort)
14
+    uptodate=$(printf "%s\n" "$uptodate_versions" | cut -d= -f1 | sort)
15
+
16
+    installed_for_update=$(comm -23 <(printf "%s\n" $installed) <(printf "%s\n" $uptodate))
17
+    packages_for_update=$(comm -12 <(printf "%s\n" $installed_for_update) <(printf "%s\n" $available))
10 18
 fi
11 19
 
12 20
 if [ -z "$packages_for_update" ]; then
@@ -18,9 +26,13 @@ PKG="$(command -v dnf || command -v yum)"
18 26
 PKG_MGR="$(echo ${PKG:(-3)})"
19 27
 
20 28
 if [ $PKG_MGR == "dnf" ]; then
21
-    $PKG install -y dnf-plugins-core
29
+    if ! echo $installed | grep -qw dnf-plugins-core; then
30
+        $PKG install -y dnf-plugins-core
31
+    fi
22 32
 else:
23
-    $PKG install -y yum-plugin-priorities
33
+    if ! echo $installed | grep -qw yum-plugin-priorities; then
34
+        $PKG install -y yum-plugin-priorities
35
+    fi
24 36
 fi
25 37
 $PKG -y update $packages_for_update
26 38
 rm -rf /var/cache/$PKG_MGR

Loading…
Cancel
Save