#!/usr/bin/env bash
# Real demos for P126 "How to Fix Django Static Files Not Loading in Production". Made on the Mac (Docker Desktop),
# like P127. One container, "dealership": a stock Ubuntu 24.04 with systemd as PID 1, Ubuntu's nginx 1.24 in front and
# gunicorn running Ana's Django site (Hillside Tractors, a tractor dealership) behind it, from a virtual environment
# with Django, gunicorn and WhiteNoise from PyPI (lab/Dockerfile, lab/tractors/). nginx's port 80 and a development
# server's port are 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); every status code is a real request.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f ce-p126-dealer >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p126-dealer lab >/dev/null
docker run -d --name ce-p126-dealer --hostname dealership -p 127.0.0.1:18126:80 -p 127.0.0.1:18226:8001 \
  --privileged --cgroupns=private -v /sys/fs/cgroup:/sys/fs/cgroup:rw --tmpfs /run --tmpfs /run/lock \
  ce-p126-dealer >/dev/null
python3 - ce-p126 < demo_driver.py
