Skip to content

Commit 5f94df5

Browse files
committed
Invalidate build cache less often
1 parent fb928a4 commit 5f94df5

1 file changed

Lines changed: 56 additions & 1 deletion

File tree

ethd

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1943,14 +1943,69 @@ __nag_os_update() {
19431943
}
19441944

19451945

1946+
__docker_df_to_bytes() {
1947+
local awk_exe
1948+
1949+
if [[ "$OSTYPE" = "darwin"* ]]; then
1950+
awk_exe="gawk" # Built-in awk can't handle multi-line. Does require brew install gawk
1951+
else
1952+
awk_exe="awk"
1953+
fi
1954+
1955+
${awk_exe} -v v="$1" '
1956+
# docker system df reports GB, not GiB
1957+
function pow1000(n, i) { r=1; for (i=0;i<n;i++) r*=1000; return r }
1958+
1959+
BEGIN {
1960+
match(v, /^([0-9.]+)([kMGTP]?B)$/, m)
1961+
1962+
num = m[1]
1963+
unit = m[2]
1964+
1965+
if (unit == "B") bytes = num
1966+
else if (unit == "kB") bytes = num * pow1000(1)
1967+
else if (unit == "MB") bytes = num * pow1000(2)
1968+
else if (unit == "GB") bytes = num * pow1000(3)
1969+
else if (unit == "TB") bytes = num * pow1000(4)
1970+
else if (unit == "PB") bytes = num * pow1000(5) # OK yes I am being silly
1971+
else bytes = 0 # In case format parsing fails
1972+
1973+
printf "%.0f\n", bytes
1974+
}
1975+
'
1976+
}
1977+
1978+
1979+
__prune_docker_cache() {
1980+
local val
1981+
local bytes
1982+
local threshold
1983+
1984+
val=$(__dodocker system df --format '{{if eq .Type "Build Cache"}}{{.Reclaimable}}{{end}}' \
1985+
| sed '/^$/d' | awk '{print $1}' || true)
1986+
if [[ ! "${val}" =~ ^[0-9.]+[kMGTP]?B$ ]]; then
1987+
echo "Docker build cache size query failed. This may be a bug."
1988+
return
1989+
fi
1990+
bytes=$(__docker_df_to_bytes "${val}")
1991+
1992+
threshold=$((50 * 1000 * 1000 * 1000 )) # 50GB
1993+
if [[ "$bytes" =~ ^[0-9]+$ && "${bytes}" -gt "${threshold}" ]]; then
1994+
echo "Pruning Docker build cache, >50GB reclaimable."
1995+
__dodocker system prune --force
1996+
fi
1997+
}
1998+
1999+
19462000
__pull_and_build() {
19472001
echo "Building local client images"
1948-
__dodocker system prune --force
2002+
__prune_docker_cache
19492003
__docompose --profile tools pull
19502004
__source_build
19512005
__docompose --profile tools build --pull
19522006
}
19532007

2008+
19542009
# Run optional pre-update hook script for custom actions before update/config.
19552010
# Users can create pre-ethd-update.sh to run validation or preparation steps.
19562011
__run_pre_update_script() {

0 commit comments

Comments
 (0)