#!/bin/sh set -eu if [ "$#" -lt 1 ]; then echo "usage: $0 /path/to/production.env [optional-api-key]" >&2 exit 2 fi deployment_env=$1 deployment_api_key=${2:-} image_name=mediarouter-deployment-gate container_name=mediarouter-deployment-gate-run-$$ docker build --tag "$image_name" . docker run \ --detach \ --name "$container_name" \ --env-file "$deployment_env" \ --publish 127.0.0.1:7860:7860 \ "$image_name" >/dev/null cleanup() { docker rm --force "$container_name" >/dev/null 2>&1 || true } trap cleanup EXIT INT TERM attempt=0 while [ "$attempt" -lt 30 ]; do health_status=$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{end}}' "$container_name") if [ "$health_status" = "healthy" ]; then break fi if [ "$(docker inspect --format '{{.State.Running}}' "$container_name")" != "true" ]; then docker logs "$container_name" exit 1 fi attempt=$((attempt + 1)) sleep 2 done if [ "${health_status:-}" != "healthy" ]; then docker logs "$container_name" echo "container did not become healthy" >&2 exit 1 fi python3 scripts/deployment_smoke.py \ --base-url http://127.0.0.1:7860 \ --api-key "$deployment_api_key" if [ "$(docker inspect --format '{{.State.Running}}' "$container_name")" != "true" ]; then echo "container stopped after smoke test" >&2 exit 1 fi echo "DOCKER_DEPLOYMENT_GATE=PASS"