#!/usr/bin/env bash
# Real demos for P165 "Kubernetes: Full Tutorial for Beginners". Runs on the Mac's Docker Desktop.
# One container, ce-p165-laptop (Ana's laptop at a community radio station): 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 and `kind create cluster`
# builds a real three-node Kubernetes cluster inside it on camera. Port 8081 (a socat relay to Ana's own
# localhost:8080, where kubectl port-forward listens) is published on the Mac's loopback as 28090, so a real browser
# can capture the page Ana opens. Every command shown is typed into a real login shell in a pty (demo_driver.py);
# Ana's files are copied into ~/radio from lab/steps off camera, as if saved from an editor, and shown with cat.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f -v ce-p165-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p165-laptop lab/laptop >/dev/null
docker run -d --name ce-p165-laptop --hostname radio-laptop --privileged --cgroupns=private \
  -p 127.0.0.1:28090:8081 \
  --tmpfs /run --tmpfs /run/lock -v /var/lib/docker -v /var/lib/containerd ce-p165-laptop >/dev/null
for i in $(seq 60); do docker exec ce-p165-laptop docker info >/dev/null 2>&1 && break; sleep 1; done
python3 demo_driver.py ce-p165-laptop
