#!/usr/bin/env bash
# Real demos for P218 "Docker vs Kubernetes: What's the Difference?". Runs on the Mac's Docker Desktop.
# One container, ce-p218-laptop (your laptop): 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. On camera, Docker builds your app's image and runs it on this one
# machine; then `kind create cluster` builds a real three-node Kubernetes cluster inside it (each node a container,
# as kind does) and Kubernetes runs the same image. Every command shown is typed into a real login shell in a pty
# (demo_driver.py); your files are copied into ~/myapp from lab/steps off camera, as if saved from an editor.
# SETUP_ONLY=1 starts the laptop and leaves it running; KEEP=1 keeps it after the run.
set -euo pipefail
cd "$(dirname "$0")"
B=ce-p218-laptop
cleanup() { docker rm -f -v $B >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}${SETUP_ONLY:-}" ] || trap cleanup EXIT
docker build -q -t $B lab/laptop >/dev/null
docker run -d --name $B --hostname laptop --privileged --cgroupns=private \
  --tmpfs /run --tmpfs /run/lock -v /var/lib/docker -v /var/lib/containerd $B >/dev/null
for i in $(seq 60); do docker exec $B docker info >/dev/null 2>&1 && break; sleep 1; done
[ -n "${SETUP_ONLY:-}" ] && exit 0
python3 demo_driver.py $B
python3 capture_docs.py
