#!/bin/bash # pybot-entrypoint: check the env, then serve the pybot world on $PORT (`python pybot.py`). # # The world keeps its own state in PYBOT_BUCKET: an empty PYBOT_WS is restored from # /world.tar.gz before it serves (a failed restore parks the world, which retries with # backoff; /healthz says "parked"), and it pushes every PYBOT_BUCKET_PUSH_S (300) and at exit # (SIGTERM, or SIGUSR1, which the server turns into SIGTERM). # # Arguments are ignored, so a launcher's placeholder command (e.g. `sleep infinity`) is harmless. # # Required env: HF_TOKEN PYBOT_REPO PYBOT_BUCKET # (hf://buckets///, or "off" for no restore and no pushes: smoke tests only), # and PYBOT_TOKEN_ for seats 0, 1, ... (agent-001, agent-002, ...): each agent's credential. # Optional: PORT (7860), PYBOT_ADMIN_TOKEN (/metrics and /admin), PYBOT_WORK (/work), every PYBOT_* # world setting, and PYBOT_SANDBOX_URL + PYBOT_SANDBOX_TOKEN (bots run in the sidecar, not under unshare here). set -euo pipefail die() { printf '%s pybot-entrypoint: FATAL: %s\n' "$(date -u +%FT%TZ)" "$*" >&2; exit 2; } for v in HF_TOKEN PYBOT_REPO PYBOT_BUCKET; do [ -n "${!v:-}" ] || die "$v is not set" done [ -n "${PYBOT_TOKEN_0:-}" ] || die "PYBOT_TOKEN_0 is not set (the agents' credentials: PYBOT_TOKEN_)" [ -z "${PYBOT_SANDBOX_URL:-}" ] || [ -n "${PYBOT_SANDBOX_TOKEN:-}" ] \ || die "PYBOT_SANDBOX_URL is set but PYBOT_SANDBOX_TOKEN is not (the sidecar would refuse every run)" case ${PYBOT_BUCKET%/} in off) unset PYBOT_BUCKET ;; # the world: no PYBOT_BUCKET = no restore and no pushes hf://buckets/*/*) ;; *) die "PYBOT_BUCKET must be hf://buckets//[/prefix] or off" ;; esac export PORT=${PORT:-7860} case $PORT in ''|*[!0-9]*|0) die "PORT=$PORT must be a positive integer";; esac WORLD=${WORLD_DIR:-/opt/world} WORK=${PYBOT_WORK:-/work} # Set here, not in the image: pyxis passes the host env (HOME, PYTHONPATH) into the container. # A host PYTHONPATH must not shadow the image's installed packages. unset PYTHONPATH export HOME=$WORK/home HF_HOME=$WORK/hf TMPDIR=$WORK/tmp export PYBOT_WS=$WORK/ws PYTHONUNBUFFERED=1 mkdir -p "$PYBOT_WS" "$HOME" "$HF_HOME" "$TMPDIR" || die "cannot create dirs under $WORK" cd "$WORLD" || die "cannot cd $WORLD" exec python pybot.py # serves on 0.0.0.0:$PORT; credentials come from the env, never argv