cloud / internal-packages / installer / test / proof-worker / redeploy.shmain at aacbc74
#!/bin/sh
# redeploy.sh — THE PROOF WORKER WITH THE STACK OF ONE GIT REF IN ITS IMAGE: packs the stack
# (../../container/pack-stack.sh), deploys the Worker, and waits until Cloudflare has rolled the
# new image out to its warm container instances. A run that starts before that gets the old image.
#
# CLOUDFLARE_API_TOKEN=… CLOUDFLARE_ACCOUNT_ID=… test/proof-worker/redeploy.sh [git ref]
set -eu
cd "$(dirname "$0")/../.."
container/pack-stack.sh "${1:-origin/main}"
OUT=$(./node_modules/.bin/wrangler deploy -c test/proof-worker/wrangler.jsonc 2>&1) || { echo "$OUT" | tail -30; exit 1; }
echo "$OUT" | grep -E 'Deployed|Version ID' || true
# the container application's id, from wrangler's table of applications
APP=$(./node_modules/.bin/wrangler containers list 2>/dev/null | awk '/iterate-access-proof-deployer/ { print $2 }')
[ -n "$APP" ] || { echo "the proof Worker's container application is not listed"; exit 1; }
# ten minutes at most; the rollout is done when no instance is starting or scheduling
for i in $(seq 1 60); do
STATE=$(./node_modules/.bin/wrangler containers info "$APP" 2>/dev/null | node -e 'let t="";process.stdin.on("data",(d)=>(t+=d)).on("end",()=>{const a=JSON.parse(t.slice(t.indexOf("{")));const h=a.health.instances;console.log(h.starting+h.scheduling===0?"done":"rolling", JSON.stringify(h))})')
case "$STATE" in done*) [ "$i" -gt 2 ] && { echo "rolled out: $STATE"; exit 0; } ;; esac
sleep 10
done
echo "the rollout did not end in ten minutes: $STATE"; exit 1