#!/usr/bin/env bash # "A developer changed one line": bump BuildInfo.REVISION, rebuild every variant, and count the # layers - and bytes - that differ from the previous build. That is what CI pushes and what every # node pulls on the next rollout. -> docs/output/rebuild-delta.txt # Run scripts/measure.sh first: it pushes the revision-1 images this compares against. set -euo pipefail source "$(dirname "$0")/env.sh" cd "$MODULE_DIR" FILE=src/main/java/com/ankurm/images/BuildInfo.java trap 'sed -i "s/REVISION = \"2\"/REVISION = \"1\"/" "$FILE"; mvn -q -o -DskipTests package' EXIT sed -i 's/REVISION = "1"/REVISION = "2"/' "$FILE" mvn -q -o -DskipTests package ./scripts/build-images.sh -r2 > /dev/null layers() { crane manifest "$1" | python3 -c 'import json,sys for l in json.load(sys.stdin)["layers"]: print(l["digest"], l["size"])'; } { echo "# One-line code change (BuildInfo.REVISION 1 -> 2), every variant rebuilt." echo "# 'new layers' = layer digests in revision 2 that revision 1 did not have: what a push uploads" echo "# and what a node that already runs revision 1 downloads." echo printf '%-20s %12s %14s %14s %s\n' variant "new layers" "bytes to push" "image total" "share" for v in "${VARIANTS[@]}"; do docker tag "sbd/docker-images:$v-r2" "$REPO:$v-r2" && docker push -q "$REPO:$v-r2" > /dev/null layers "$REPO:$v" | sort > /tmp/r1; layers "$REPO:$v-r2" | sort > /tmp/r2 new=$(comm -13 <(cut -d' ' -f1 /tmp/r1) <(cut -d' ' -f1 /tmp/r2)) count=$(echo "$new" | grep -c . || true) bytes=0; for d in $new; do bytes=$(( bytes + $(grep "^$d " /tmp/r2 | cut -d' ' -f2) )); done total=$(awk '{s+=$2} END {print s}' /tmp/r2) printf '%-20s %6s of %-3s %13sK %13sM %5.1f%%\n' "$v" "$count" "$(wc -l < /tmp/r2)" "$(( bytes / 1000 ))" "$(( total / 1000000 ))" \ "$(python3 -c "print(100*$bytes/$total)")" done } | tee "$OUT/rebuild-delta.txt"