#!/usr/bin/env bash
# Real demos for P158 "Golang defer Statements in 5 Minutes". Made on the Mac (Docker Desktop).
# Rich runs the watering box of a community vegetable patch, in Go, ~/patch. One container from a stock Ubuntu 24.04
# image (lab/Dockerfile) with Go copied in from the official golang image, started with Ubuntu's usual open-file
# limit of 1024. Each version of the Go files Rich types waits in lab/steps/<name>/ and is copied in off camera; one
# real interactive bash in a pty (demo_driver.py) and every line of output is real.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f ce-p158-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p158 lab >/dev/null
docker run -d --name ce-p158-laptop --hostname laptop --ulimit nofile=1024:1024 ce-p158 >/dev/null
python3 demo_driver.py
