#!/usr/bin/env bash # Deploy token-aggregation service for publication (token lists, CoinGecko/CMC reports, bridge/routes). # Run on explorer VM (VMID 5000) or host that serves explorer.d-bis.org. # # Prerequisites: Node 20+, PostgreSQL (for full indexing; API responds with defaults if DB empty) # Usage: ./scripts/deploy-token-aggregation-for-publication.sh [INSTALL_DIR] # # After deploy: nginx must proxy /api/v1/ to this service BEFORE Blockscout (see TOKEN_AGGREGATION_REPORT_API_RUNBOOK). # Explorer layouts vary: port 3000 or 3001 — match TOKEN_AGG_PORT in apply-nginx scripts. set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" INSTALL_DIR="${1:-$REPO_ROOT/token-aggregation-build}" SVC_DIR="$REPO_ROOT/smom-dbis-138/services/token-aggregation" if [ ! -d "$SVC_DIR" ]; then echo "Token-aggregation not found at $SVC_DIR" >&2 exit 1 fi echo "Deploying token-aggregation to $INSTALL_DIR" mkdir -p "$INSTALL_DIR" cp -a "$SVC_DIR"/* "$INSTALL_DIR/" cd "$INSTALL_DIR" if [ ! -f .env ]; then if [ -f .env.example ]; then cp .env.example .env echo "Created .env from .env.example — set DATABASE_URL for persistent index; CUSDT/CUSDC already defaulted." else echo "Create .env with at least DATABASE_URL (and optional CHAIN_138_RPC_URL)." >&2 fi fi if command -v pnpm >/dev/null 2>&1 && [ -f "$REPO_ROOT/pnpm-lock.yaml" ]; then (cd "$REPO_ROOT" && pnpm install --filter token-aggregation-service --no-frozen-lockfile 2>/dev/null) || true fi npm install --omit=dev 2>/dev/null || npm install npm run build echo "" echo "Token-aggregation built. Start with:" echo " cd $INSTALL_DIR && node dist/index.js" echo "Or add systemd unit. Default port from code: 3000 (match nginx TOKEN_AGG_PORT / fix-explorer-http-api-v1-proxy.sh uses 3001)." echo "" echo "Then apply nginx proxy (on same host), e.g.:" echo " TOKEN_AGG_PORT=3001 CONFIG_FILE=/etc/nginx/sites-available/blockscout \\" echo " bash $REPO_ROOT/scripts/fix-explorer-http-api-v1-proxy.sh" echo " # or: explorer-monorepo/scripts/apply-nginx-token-aggregation-proxy.sh" echo "" echo "Verify:" echo " pnpm run verify:token-aggregation-api" echo " SKIP_BRIDGE_ROUTES=0 bash scripts/verify/check-public-report-api.sh https://explorer.d-bis.org"