#!/usr/bin/env bash
# Real demos for P179 "Nginx: Full Tutorial for Beginners".
# Runs one stock Ubuntu 24.04 systemd container (`web`) with Ubuntu's nginx, two real gunicorn app instances
# (127.0.0.1:8001 and 127.0.0.1:8002), curl, and openssl. Every command runs in a real interactive bash pty
# (`demo_driver.py`) and writes literal measured output to `demo_output.json`.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f ce-p179-web >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p179-web lab >/dev/null
docker run -d --name ce-p179-web --hostname web \
  --privileged --cgroupns=private \
  -v /sys/fs/cgroup:/sys/fs/cgroup:rw \
  --tmpfs /run --tmpfs /run/lock \
  ce-p179-web >/dev/null
python3 demo_driver.py ce-p179-web
