#!/usr/bin/env bash
# Real demos for P194 "Amazon Bedrock vs OpenRouter: Which One Should You Use?". Made on the Mac (Docker Desktop).
# Dave keeps the computers of a small airplane hangar and is building a maintenance assistant. Two containers on one
# Docker network:
#   laptop   Dave's laptop: stock Ubuntu 24.04, the AWS CLI v2 copied from the official amazon/aws-cli image, curl, jq
#   aws      Floci, a local AWS emulator (image pinned by digest), standing in for Amazon Bedrock. Its bedrock-runtime
#            runs in proxy mode: the Converse request is real AWS (SigV4-signed by the AWS CLI with an access key Floci
#            issued to an IAM user "dave"), and Floci passes it to a free model on OpenRouter for the answer, which
#            the video says on screen. We have no Bedrock account in the lab, and real Bedrock bills every token.
# OpenRouter calls go to the real openrouter.ai with our free-tier key ($0 limit: free models only), passed into the
# laptop as an environment variable and never printed. One real interactive bash in a pty (demo_driver.py).
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p194
FLOCI=floci/floci@sha256:a0fbf944d7f338cc0856f1ef83831ea749ff2be71956eb7a7fce08fc21458e19
KEY_FILE="${OPENROUTER_KEY_FILE:-$HOME/cloudexplainers/.openrouter_api_key}"
cleanup() { docker rm -f $P-laptop $P-aws >/dev/null 2>&1 || true; docker network rm $P >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker network create $P >/dev/null
docker run -d --name $P-aws --hostname aws --network $P \
  -e FLOCI_SERVICES_BEDROCK_RUNTIME_BACKEND=proxy \
  -e FLOCI_SERVICES_BEDROCK_RUNTIME_PROXY_URL=https://openrouter.ai/api/v1 \
  -e FLOCI_SERVICES_BEDROCK_RUNTIME_PROXY_API_KEY="$(cat "$KEY_FILE")" \
  -e FLOCI_SERVICES_BEDROCK_RUNTIME_PROXY_DEFAULT_MODEL=baidu/ernie-5.5-flash-preview:free \
  $FLOCI >/dev/null
docker build -q -t $P lab >/dev/null
docker run -d --name $P-laptop --hostname laptop --network $P -e OPENROUTER_API_KEY="$(cat "$KEY_FILE")" $P >/dev/null
python3 demo_driver.py
