@@ -2026,14 +2026,69 @@ __nag_os_update() {
20262026}
20272027
20282028
2029+ __docker_df_to_bytes () {
2030+ local awk_exe
2031+
2032+ if [[ " $OSTYPE " = " darwin" * ]]; then
2033+ awk_exe=" gawk" # Built-in awk can't handle multi-line. Does require brew install gawk
2034+ else
2035+ awk_exe=" awk"
2036+ fi
2037+
2038+ ${awk_exe} -v v=" $1 " '
2039+ # docker system df reports GB, not GiB
2040+ function pow1000(n, i) { r=1; for (i=0;i<n;i++) r*=1000; return r }
2041+
2042+ BEGIN {
2043+ match(v, /^([0-9.]+)([kMGTP]?B)$/, m)
2044+
2045+ num = m[1]
2046+ unit = m[2]
2047+
2048+ if (unit == "B") bytes = num
2049+ else if (unit == "kB") bytes = num * pow1000(1)
2050+ else if (unit == "MB") bytes = num * pow1000(2)
2051+ else if (unit == "GB") bytes = num * pow1000(3)
2052+ else if (unit == "TB") bytes = num * pow1000(4)
2053+ else if (unit == "PB") bytes = num * pow1000(5) # OK yes I am being silly
2054+ else bytes = 0 # In case format parsing fails
2055+
2056+ printf "%.0f\n", bytes
2057+ }
2058+ '
2059+ }
2060+
2061+
2062+ __prune_docker_cache () {
2063+ local val
2064+ local bytes
2065+ local threshold
2066+
2067+ val=$( __dodocker system df --format ' {{if eq .Type "Build Cache"}}{{.Reclaimable}}{{end}}' \
2068+ | sed ' /^$/d' | awk ' {print $1}' || true)
2069+ if [[ ! " ${val} " =~ ^[0-9.]+[kMGTP]? B$ ]]; then
2070+ echo " Docker build cache size query failed. This may be a bug."
2071+ return
2072+ fi
2073+ bytes=$( __docker_df_to_bytes " ${val} " )
2074+
2075+ threshold=$(( 50 * 1000 * 1000 * 1000 )) # 50GB
2076+ if [[ " $bytes " =~ ^[0-9]+$ && " ${bytes} " -gt " ${threshold} " ]]; then
2077+ echo " Pruning Docker build cache, >50GB reclaimable."
2078+ __dodocker system prune --force
2079+ fi
2080+ }
2081+
2082+
20292083__pull_and_build () {
20302084 echo " Building local client images"
2031- __dodocker system prune --force
2085+ __prune_docker_cache
20322086 __docompose --profile tools pull
20332087 __source_build
20342088 __docompose --profile tools build --pull
20352089}
20362090
2091+
20372092# Run optional pre-update hook script for custom actions before update/config.
20382093# Users can create pre-ethd-update.sh to run validation or preparation steps.
20392094__run_pre_update_script () {
0 commit comments