#!/usr/bin/env bash
# Real demos for P212 "How API Webhooks Work". Runs on the Mac (Docker Desktop): the GitHub token lives only on the
# Mac, never on a render box.
# One container, ce-p212-laptop: a stock Ubuntu 24.04 with Python 3.12 + Flask, git, gh, curl, jq and Cloudflare's
# cloudflared (lab/Dockerfile), the receiver's versions in ~/app. GitHub is real: a private lab repository,
# cloudexplainers/webhooks-lab (made by the first run; the token can't delete repositories, so it stays), gets a real
# webhook that points at a real Cloudflare quick tunnel to the receiver on the laptop. demo_driver.py types every
# command into real interactive bash shells in ptys, deletes the webhook at the end and writes demo_output.json.
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p212
cleanup() { docker rm -f $P-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-laptop lab >/dev/null
docker run -d --name $P-laptop --hostname laptop --dns 1.1.1.1 $P-laptop sleep infinity >/dev/null
python3 demo_driver.py
