Files
proxmox/scripts/deployment/sync-mev-control-gui-defi-oracle.sh
defiQUG 075a9c8a3c feat: deploy MEV Control GUI to mev.defi-oracle.io (nginx, NPM, Cloudflare)
- Add nginx site template + sync-mev-control-gui-defi-oracle.sh
- NPM fleet: mev.defi-oracle.io + www.mev; Cloudflare set-mev-defi-oracle-dns.sh
- ip-addresses + .env.master.example: MEV_ADMIN_API_* and web root vars
- Runbook MEV_CONTROL_DEFI_ORACLE_IO_DEPLOYMENT.md; AGENTS, MASTER_INDEX, ALL_VMIDS

Made-with: Cursor
2026-04-12 18:48:02 -07:00

114 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build MEV Control (Vite GUI from MEV_Bot) and sync to the defi-oracle.io nginx LXC.
#
# Default: VMID 2410 (same host as info.defi-oracle.io), /var/www/mev.defi-oracle.io/html
# Nginx proxies /api/* to mev-admin-api (override MEV_ADMIN_API_HOST / MEV_ADMIN_API_PORT).
#
# Usage (repo root, LAN + SSH to Proxmox):
# bash scripts/deployment/sync-mev-control-gui-defi-oracle.sh [--dry-run]
# Then:
# bash scripts/nginx-proxy-manager/update-npmplus-proxy-hosts-api.sh
# bash scripts/cloudflare/set-mev-defi-oracle-dns.sh # if using Cloudflare zone defi-oracle.io
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
cd "$PROJECT_ROOT"
source "$PROJECT_ROOT/config/ip-addresses.conf" 2>/dev/null || true
if [[ -f "$PROJECT_ROOT/.env" ]]; then
set +u
# shellcheck source=/dev/null
source "$PROJECT_ROOT/.env" 2>/dev/null || true
set -u
fi
source "$PROJECT_ROOT/config/ip-addresses.conf" 2>/dev/null || true
PROXMOX_HOST="${PROXMOX_HOST:-${PROXMOX_HOST_R630_01:-192.168.11.11}}"
VMID="${MEV_DEFI_ORACLE_WEB_VMID:-${INFO_DEFI_ORACLE_WEB_VMID:-2410}}"
APP_DIR="${MEV_DEFI_ORACLE_WEB_ROOT:-/var/www/mev.defi-oracle.io/html}"
SITE_AVAILABLE="${MEV_DEFI_ORACLE_NGINX_SITE:-/etc/nginx/sites-available/mev-defi-oracle}"
NGINX_TEMPLATE="${PROJECT_ROOT}/config/nginx/mev-defi-oracle-io.site.conf.template"
MEV_ADMIN_API_HOST="${MEV_ADMIN_API_HOST:-192.168.11.11}"
MEV_ADMIN_API_PORT="${MEV_ADMIN_API_PORT:-9090}"
MEV_ADMIN_UPSTREAM="http://${MEV_ADMIN_API_HOST}:${MEV_ADMIN_API_PORT}"
GUI_DIR="${PROJECT_ROOT}/MEV_Bot/mev-platform/gui"
SSH_OPTS="-o BatchMode=yes -o ConnectTimeout=15 -o StrictHostKeyChecking=accept-new"
DRY_RUN=false
[[ "${1:-}" == "--dry-run" ]] && DRY_RUN=true
if [[ ! -d "$GUI_DIR" ]]; then
echo "ERROR: Missing $GUI_DIR (init MEV_Bot submodule: git submodule update --init MEV_Bot)" >&2
exit 1
fi
if [[ ! -f "$NGINX_TEMPLATE" ]]; then
echo "ERROR: Missing $NGINX_TEMPLATE" >&2
exit 1
fi
echo "=== Sync MEV Control GUI → mev.defi-oracle.io (VMID ${VMID}) ==="
echo "Proxmox: ${PROXMOX_HOST} Admin API upstream: ${MEV_ADMIN_UPSTREAM}"
TMP_NGINX="$(mktemp)"
TMP_TGZ="${TMPDIR:-/tmp}/mev-gui-sync-$$.tgz"
REMOTE_TGZ="/tmp/mev-gui-sync-$$.tgz"
REMOTE_NGINX="/tmp/mev-defi-oracle-site-$$.conf"
CT_TGZ="/tmp/mev-gui-sync.tgz"
cleanup() { rm -f "$TMP_NGINX" "$TMP_TGZ"; }
trap cleanup EXIT
sed "s@__MEV_ADMIN_API_UPSTREAM__@${MEV_ADMIN_UPSTREAM}@g" "$NGINX_TEMPLATE" >"$TMP_NGINX"
if $DRY_RUN; then
echo "[DRY-RUN] npm ci + npm run build in $GUI_DIR"
echo "[DRY-RUN] tar dist -> tgz, scp, pct push ${VMID}, nginx site -> ${SITE_AVAILABLE}"
exit 0
fi
if ! command -v npm >/dev/null 2>&1; then
echo "ERROR: npm is required to build the GUI." >&2
exit 1
fi
echo "Building GUI..."
(cd "$GUI_DIR" && npm ci && npm run build)
echo "Packaging dist/..."
tar czf "$TMP_TGZ" -C "$GUI_DIR/dist" .
echo "Copying to Proxmox host ${PROXMOX_HOST}..."
scp $SSH_OPTS "$TMP_TGZ" "root@${PROXMOX_HOST}:${REMOTE_TGZ}"
scp $SSH_OPTS "$TMP_NGINX" "root@${PROXMOX_HOST}:${REMOTE_NGINX}"
echo "Installing into VMID ${VMID}..."
ssh $SSH_OPTS "root@${PROXMOX_HOST}" bash -s "$VMID" "$REMOTE_TGZ" "$CT_TGZ" "$APP_DIR" "$SITE_AVAILABLE" "$REMOTE_NGINX" <<'REMOTE'
set -euo pipefail
VMID="$1"
REMOTE_TGZ="$2"
CT_TGZ="$3"
APP_DIR="$4"
SITE_FILE="$5"
REMOTE_NGINX="$6"
pct push "$VMID" "$REMOTE_TGZ" "$CT_TGZ"
rm -f "$REMOTE_TGZ"
pct exec "$VMID" -- bash -lc "mkdir -p '$APP_DIR' && rm -rf '${APP_DIR}'/* && tar xzf '$CT_TGZ' -C '$APP_DIR' && rm -f '$CT_TGZ'"
pct push "$VMID" "$REMOTE_NGINX" "$SITE_FILE"
rm -f "$REMOTE_NGINX"
pct exec "$VMID" -- bash -lc "mkdir -p /var/www/mev.defi-oracle.io/html && ln -sf '$SITE_FILE' /etc/nginx/sites-enabled/mev-defi-oracle"
pct exec "$VMID" -- nginx -t
pct exec "$VMID" -- systemctl reload nginx
sleep 1
pct exec "$VMID" -- curl -fsS -H 'Host: mev.defi-oracle.io' "http://127.0.0.1/health" | grep -q mev-gui-healthy
REMOTE
echo ""
echo "✅ GUI synced. Next:"
echo " NPM: bash scripts/nginx-proxy-manager/update-npmplus-proxy-hosts-api.sh"
echo " DNS: bash scripts/cloudflare/set-mev-defi-oracle-dns.sh"
echo " Ensure mev-admin-api listens on ${MEV_ADMIN_UPSTREAM} (reachable from CT ${VMID})."