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
55 lines
3.0 KiB
Bash
Executable File
55 lines
3.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Jib vs Buildpacks on the same application: size, layers, rebuild time, runtime memory. Timings are indicative.
|
|
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
|
|
t() { local s=$SECONDS; "$@" >/tmp/compare-step.log 2>&1 || { tail -20 /tmp/compare-step.log; return 1; }; echo $((SECONDS-s)); }
|
|
{
|
|
banner "Cold builds (Jib: local Jib cache removed; Buildpacks: cleanCache=true), seconds"
|
|
rm -rf ~/.cache/google-cloud-tools-java/jib target/jib-cache
|
|
echo "jib cold: $(t "${MVN[@]}" clean compile jib:dockerBuild "${BASE_ARG[@]}")"
|
|
echo "buildpacks cold: $(t "${MVN[@]}" clean spring-boot:build-image -Dspring-boot.build-image.cleanCache=true "${BP_ARGS[@]}")"
|
|
|
|
banner "Warm rebuilds after a one-line change, seconds"
|
|
sed -i 's/hello from a Jib image/hello warm/' "$SRC"
|
|
echo "jib warm: $(t "${MVN[@]}" compile jib:dockerBuild "${BASE_ARG[@]}")"
|
|
echo "buildpacks warm: $(t "${MVN[@]}" spring-boot:build-image "${BP_ARGS[@]}")"
|
|
cp /tmp/HelloController.orig "$SRC"
|
|
"${MVN[@]}" -q compile jib:dockerBuild "${BASE_ARG[@]}" >/dev/null 2>&1
|
|
"${MVN[@]}" -q spring-boot:build-image "${BP_ARGS[@]}" >/dev/null 2>&1
|
|
|
|
banner "Images (docker image inspect)"
|
|
for img in jib-demo:1.0.0 jib-demo:buildpacks; do
|
|
docker image inspect "$img" --format '{{index .RepoTags 0}} size={{.Size}} layers={{len .RootFS.Layers}} created={{.Created}} user={{.Config.User}}'
|
|
done
|
|
|
|
banner "Is there a shell in the final image? (docker run --entrypoint sh ... -c 'echo yes')"
|
|
for img in jib-demo:1.0.0 jib-demo:buildpacks; do
|
|
printf '%-22s ' "$img"; docker run --rm --entrypoint sh "$img" -c 'echo yes' 2>&1 | head -1 | cut -c1-260 || true
|
|
done
|
|
|
|
banner "Run each image under a memory limit"
|
|
run_case() { # run_case <image> <memory> [extra docker args...]
|
|
local img=$1 mem=$2; shift 2
|
|
docker rm -f cmp >/dev/null 2>&1 || true
|
|
docker run -d --name cmp -m "$mem" -p 18081:8080 "$@" "$img" >/dev/null
|
|
for i in $(seq 1 60); do curl -s -o /dev/null localhost:18081/actuator/health && break; \
|
|
[ "$(docker inspect -f '{{.State.Running}}' cmp)" = true ] || break; sleep 1; done
|
|
echo "--- $img memory=$mem $*"
|
|
if [ "$(docker inspect -f '{{.State.Running}}' cmp)" = true ]; then
|
|
curl -s localhost:18081/hello; echo
|
|
docker stats --no-stream --format 'container memory in use: {{.MemUsage}}' cmp
|
|
else
|
|
echo "container exited with code $(docker inspect -f '{{.State.ExitCode}}' cmp)"
|
|
fi
|
|
docker logs cmp 2>&1 | grep -E 'Memory Configuration|Setting Active Processor|unable to calculate|fixed memory|Started JibDemoApplication' | sed -E 's/^[0-9T:.Z-]+ +//' | cut -c1-260
|
|
docker rm -f cmp >/dev/null 2>&1 || true
|
|
}
|
|
run_case jib-demo:1.0.0 512m
|
|
run_case jib-demo:buildpacks 512m
|
|
run_case jib-demo:buildpacks 512m -e BPL_JVM_THREAD_COUNT=50
|
|
run_case jib-demo:buildpacks 1g
|
|
} 2>&1 | clean | tee "$OUT/07-compare.txt"
|
|
cp /tmp/HelloController.orig "$SRC"
|