#!/usr/bin/env bash
# Real demos for P141 "How to Fix a Kubernetes Pod Stuck in CrashLoopBackOff". Runs on the Mac's Docker Desktop.
# One container, ce-p141-laptop (Jim's laptop at Riverside Pool, a small public swimming pool): a stock Ubuntu
# 24.04 with systemd as PID 1, Ubuntu's own Docker, and kind + kubectl from their official releases
# (lab/laptop/Dockerfile), run --privileged with its own cgroup namespace and fresh volumes, so its Docker starts empty.
# Off camera, demo_driver.py makes a real two-node kind cluster inside it. Every command shown is typed into a real
# login shell in a pty; Jim's files are copied into ~/lanes from lab/steps off camera, as if saved from an editor.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f -v ce-p141-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p141-laptop lab/laptop >/dev/null
docker run -d --name ce-p141-laptop --hostname pool-laptop --privileged --cgroupns=private \
  --tmpfs /run --tmpfs /run/lock -v /var/lib/docker -v /var/lib/containerd ce-p141-laptop >/dev/null
for i in $(seq 60); do docker exec ce-p141-laptop docker info >/dev/null 2>&1 && break; sleep 1; done
python3 demo_driver.py ce-p141-laptop
