Same app built both ways: layers, reproducible digest, extraDirectories, registry push without a daemon, wrong-JRE and missing-compile failures, Buildpacks memory calculator at 512 MB. Captured output in jib/output, regenerated by jib/scripts/run-all.sh. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
36 lines
1.7 KiB
Bash
Executable File
36 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Change one line of application code and see which layers of the image change.
|
|
source "$(dirname "$0")/lib.sh"
|
|
SRC=src/main/java/com/ankurm/jibdemo/HelloController.java
|
|
cp "$SRC" /tmp/HelloController.orig
|
|
trap 'cp /tmp/HelloController.orig "$SRC"' EXIT
|
|
|
|
# Print "<layer digest prefix> <size in bytes>" for every layer file in the tarball Jib wrote.
|
|
layers() {
|
|
rm -rf /tmp/jibtar && mkdir /tmp/jibtar && tar -xf target/jib-image.tar -C /tmp/jibtar
|
|
python3 - <<'PY'
|
|
import json, os, tarfile
|
|
d = "/tmp/jibtar"
|
|
m = json.load(open(f"{d}/manifest.json"))[0]
|
|
for name in m["Layers"][-5:]: # the five layers Jib added; the base image layers come first
|
|
t = tarfile.open(f"{d}/{name}")
|
|
files = [m.name for m in t.getmembers() if not m.isdir()]
|
|
print(name.replace(".tar.gz", "")[:12], f"{os.path.getsize(f'{d}/{name}'):>9} bytes", f"{len(files):>3} files", files[0])
|
|
PY
|
|
}
|
|
{
|
|
banner "Build 1: unchanged source"
|
|
"${MVN[@]}" -q clean compile jib:buildTar "${BASE_ARG[@]}" >/dev/null 2>&1
|
|
layers | tee /tmp/layers1.txt
|
|
banner "Edit one string in HelloController.java, then build 2"
|
|
sed -i 's/hello from a Jib image/hello again/' "$SRC"
|
|
"${MVN[@]}" -q clean compile jib:buildTar "${BASE_ARG[@]}" >/dev/null 2>&1
|
|
layers | tee /tmp/layers2.txt
|
|
banner "Layers whose digest changed (< build 1, > build 2)"
|
|
diff <(awk '{print $1}' /tmp/layers1.txt) <(awk '{print $1}' /tmp/layers2.txt) | grep '^[<>]' || true
|
|
banner "Files in the layer that changed"
|
|
NEW=$(diff <(awk '{print $1}' /tmp/layers1.txt) <(awk '{print $1}' /tmp/layers2.txt) | grep '^>' | head -1 | cut -c3- || true)
|
|
tar -tzf /tmp/jibtar/${NEW}*.tar.gz 2>/dev/null | grep -v '/$'
|
|
} 2>&1 | clean | tee "$OUT/04-layer-cache.txt"
|
|
cp /tmp/HelloController.orig "$SRC"
|