#!/usr/bin/env bash
# Real demos for P112 "REST vs gRPC: Which One Should You Use?". Made on the Mac with Docker Desktop.
# Two machines on their own internal Docker network (nothing leaves the Mac), from one image (lab/Dockerfile):
#   stock    Ana's stock service: the same tea stock behind REST (FastAPI, port 8000) and gRPC (port 50051)
#   laptop   Ana's order service: curl, grpcurl and small Python clients (httpx, grpcio)
# Every command shown is typed into a real interactive bash in a pty (demo_driver.py): one window on the stock
# machine, two on the laptop (one of them watches a gRPC stream).
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p112
cleanup() { docker rm -f $P-stock $P-laptop >/dev/null 2>&1 || true; docker network rm $P-net >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P lab >/dev/null
docker network create --internal $P-net >/dev/null
docker run -d --name $P-stock --hostname stock --network $P-net --network-alias stock $P >/dev/null
docker run -d --name $P-laptop --hostname laptop --network $P-net $P >/dev/null
python3 - "$P" < demo_driver.py
