#!/bin/bash # one-line change = a value never built before, so the cache can't already hold it cd "$(dirname "$0")" for d in cache-bad cache-good; do echo "print('base')" > $d/main.py docker build -q -t ctr-$d $d >/dev/null echo "print('$(date +%s)-$RANDOM')" > $d/main.py s=$(python3 -c 'import time;print(time.time())') docker build --progress=plain -t ctr-$d $d > $d.log 2>&1 e=$(python3 -c 'import time;print(time.time())') grep -E '^#[0-9]+ (\[[0-9]/[0-9]\]|CACHED|DONE)' $d.log | grep -v 'load\|metadata' | sed 's/^/ /' printf '%s rebuild after one-line change: %.1fs\n' $d "$(python3 -c "print($e-$s)")" done