Files
proxmox/scripts/deployment/deploy-mev-backend-ct2421-latest.sh
defiQUG cba978f656
All checks were successful
Deploy to Phoenix / deploy (push) Successful in 11s
Tighten MEV rollout verification and deploy timeouts
2026-04-14 17:19:50 -07:00

178 lines
5.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
PVE_HOST="${MEV_BACKEND_PVE_HOST:-192.168.11.14}"
CT_VMID="${MEV_BACKEND_CT_VMID:-2421}"
CT_ROOT="${MEV_BACKEND_CT_ROOT:-/opt/proxmox/MEV_Bot}"
MEV_DIR="${MEV_BACKEND_MEV_DIR:-$CT_ROOT/mev-platform}"
MEV_BRANCH="${MEV_BACKEND_BRANCH:-master}"
PARENT_BRANCH="${MEV_BACKEND_PARENT_BRANCH:-master}"
API_KEY="${MEV_API_KEY:-}"
SSH_CONNECT_TIMEOUT="${MEV_BACKEND_SSH_CONNECT_TIMEOUT:-10}"
SSH_SERVER_ALIVE_INTERVAL="${MEV_BACKEND_SSH_SERVER_ALIVE_INTERVAL:-10}"
SSH_SERVER_ALIVE_COUNT_MAX="${MEV_BACKEND_SSH_SERVER_ALIVE_COUNT_MAX:-6}"
REMOTE_TIMEOUT_SECONDS="${MEV_BACKEND_REMOTE_TIMEOUT_SECONDS:-1800}"
APPLY=0
usage() {
cat <<'EOF'
Usage: deploy-mev-backend-ct2421-latest.sh [options]
Fast-forward the MEV backend checkout inside CT 2421, rebuild the backend
services in-place, restart the control plane, and run local verification.
Defaults to dry-run. Re-run with --apply to execute.
Options:
--pve-host HOST Proxmox host running the MEV backend CT (default: 192.168.11.14)
--ct-vmid VMID MEV backend CT VMID (default: 2421)
--ct-root PATH Parent repo path inside the CT (default: /opt/proxmox/MEV_Bot)
--mev-dir PATH MEV submodule path inside the CT (default: /opt/proxmox/MEV_Bot/mev-platform)
--branch NAME mev-platform branch to fast-forward (default: master)
--parent-branch NAME MEV_Bot branch to fast-forward (default: master)
--api-key KEY Optional API key for protected verification routes
--remote-timeout SEC Max remote execution time before timeout (default: 1800)
--dry-run Print the planned remote command (default behavior)
--apply Execute the deployment
-h, --help Show this help
EOF
}
while [[ $# -gt 0 ]]; do
case "$1" in
--pve-host)
PVE_HOST="$2"
shift 2
;;
--ct-vmid)
CT_VMID="$2"
shift 2
;;
--ct-root)
CT_ROOT="$2"
shift 2
;;
--mev-dir)
MEV_DIR="$2"
shift 2
;;
--branch)
MEV_BRANCH="$2"
shift 2
;;
--parent-branch)
PARENT_BRANCH="$2"
shift 2
;;
--api-key)
API_KEY="$2"
shift 2
;;
--remote-timeout)
REMOTE_TIMEOUT_SECONDS="$2"
shift 2
;;
--dry-run)
APPLY=0
shift
;;
--apply)
APPLY=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage >&2
exit 2
;;
esac
done
require_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "Required command missing: $1" >&2
exit 2
}
}
require_cmd ssh
require_cmd bash
REMOTE_CMD=$(cat <<EOF
set -euo pipefail
command -v timeout >/dev/null 2>&1 || { echo "missing timeout inside CT" >&2; exit 127; }
timeout ${REMOTE_TIMEOUT_SECONDS}s bash -lc '
cd "$CT_ROOT"
echo "== parent repo =="
git fetch origin
git checkout "$PARENT_BRANCH"
git pull --ff-only origin "$PARENT_BRANCH"
echo "== submodule pointer =="
git submodule update --init --recursive mev-platform
cd "$MEV_DIR"
echo "== mev-platform repo =="
git fetch origin
git checkout "$MEV_BRANCH"
git pull --ff-only origin "$MEV_BRANCH"
echo "== build release binaries =="
cargo build --release -p mev-admin-api -p mev-supervisor \\
-p mev-pool-indexer -p mev-state-ingestion -p mev-liquidity-graph \\
-p mev-opportunity-search -p mev-simulation -p mev-bundle-builder \\
-p mev-execution-gateway -p mev-settlement-analytics
echo "== restart services =="
systemctl restart mev-supervisor.service
systemctl restart mev-admin-api.service
systemctl restart mev-start-all.service || systemctl start mev-start-all.service || true
echo "== local health =="
curl -fsS http://127.0.0.1:9090/api/health
echo
curl -fsS http://127.0.0.1:9090/api/infra
echo
curl -fsS http://127.0.0.1:9090/api/stats/freshness
echo
if [ -n "${API_KEY}" ]; then
curl -fsS -H "X-API-Key: ${API_KEY}" http://127.0.0.1:9090/api/stats/ops
echo
curl -fsS -H "X-API-Key: ${API_KEY}" http://127.0.0.1:9090/api/stats/metrics-surfaces
echo
fi
'
EOF
)
echo "MEV backend deploy helper"
echo "PVE host: $PVE_HOST"
echo "CT VMID: $CT_VMID"
echo "CT root: $CT_ROOT"
echo "MEV dir: $MEV_DIR"
echo "Parent branch: $PARENT_BRANCH"
echo "MEV branch: $MEV_BRANCH"
echo "SSH timeout: ${SSH_CONNECT_TIMEOUT}s connect, ${SSH_SERVER_ALIVE_INTERVAL}s keepalive x ${SSH_SERVER_ALIVE_COUNT_MAX}"
echo "Remote limit: ${REMOTE_TIMEOUT_SECONDS}s"
echo "Apply: $APPLY"
echo
echo "Planned remote command:"
echo "ssh -o BatchMode=yes -o ConnectTimeout=$SSH_CONNECT_TIMEOUT -o ServerAliveInterval=$SSH_SERVER_ALIVE_INTERVAL -o ServerAliveCountMax=$SSH_SERVER_ALIVE_COUNT_MAX root@$PVE_HOST \"pct exec $CT_VMID -- bash -lc $(printf '%q' "$REMOTE_CMD")\""
if [[ "$APPLY" -ne 1 ]]; then
echo
echo "Dry-run only. Re-run with --apply to execute."
exit 0
fi
ssh \
-o BatchMode=yes \
-o ConnectTimeout="$SSH_CONNECT_TIMEOUT" \
-o ServerAliveInterval="$SSH_SERVER_ALIVE_INTERVAL" \
-o ServerAliveCountMax="$SSH_SERVER_ALIVE_COUNT_MAX" \
"root@$PVE_HOST" \
"pct exec $CT_VMID -- bash -lc $(printf '%q' "$REMOTE_CMD")"