#!/usr/bin/env bash
# Real demos for P093 "How to Fix Python cron Jobs That Never Run". Made on the Mac (Docker Desktop), like P101.
# One container, "bikes": a stock Ubuntu 24.04 with systemd as PID 1, so cron is the real service and its log is in
# the journal (lab/Dockerfile). Ana's project (lab/bikes/: report.py and rentals.csv) is copied in, her virtual
# environment gets requests from PyPI, and her ~/.bashrc exports the shop's made-up key, all before the story starts.
# The shop's dashboard (lab/dashboard/app.py) runs in the same container; its port is published to this Mac's
# localhost only, for the real browser captures (lab/capture.py). Every command shown is typed into a real interactive
# bash in a pty (demo_driver.py), and every cron job really runs at its minute: the driver waits for it.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f ce-p093-bikes >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p093-bikes lab >/dev/null
docker run -d --name ce-p093-bikes --hostname bikes -p 127.0.0.1:18093:8000 \
  --privileged --cgroupns=private -v /sys/fs/cgroup:/sys/fs/cgroup:rw --tmpfs /run --tmpfs /run/lock \
  ce-p093-bikes >/dev/null
python3 - ce-p093 < demo_driver.py
