#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" SUBMODULE_ROOT="$PROJECT_ROOT/atomic-swap-dapp" source "$PROJECT_ROOT/config/ip-addresses.conf" 2>/dev/null || true PROXMOX_HOST="${PROXMOX_HOST:-${PROXMOX_HOST_R630_02:-192.168.11.12}}" VMID="${VMID:-5801}" DEPLOY_ROOT="${DEPLOY_ROOT:-/var/www/atomic-swap}" TMP_ARCHIVE="/tmp/atomic-swap-dapp-5801.tgz" DIST_DIR="$SUBMODULE_ROOT/dist" SKIP_BUILD="${SKIP_BUILD:-0}" cleanup() { rm -f "$TMP_ARCHIVE" } trap cleanup EXIT if [ ! -d "$SUBMODULE_ROOT" ]; then echo "Missing submodule at $SUBMODULE_ROOT" >&2 exit 1 fi cd "$SUBMODULE_ROOT" if [ "$SKIP_BUILD" != "1" ]; then npm run sync:ecosystem >/dev/null npm run validate:manifest >/dev/null npm run build >/dev/null fi for required_path in \ "$DIST_DIR/index.html" \ "$DIST_DIR/data/ecosystem-manifest.json" \ "$DIST_DIR/data/live-route-registry.json" \ "$DIST_DIR/data/deployed-venue-inventory.json"; do if [ ! -f "$required_path" ]; then echo "Missing required build artifact: $required_path" >&2 exit 1 fi done jq -e '.supportedNetworks[] | select(.chainId == 138) | .deployedVenuePoolCount >= 19 and .publicRoutingPoolCount >= 19' \ "$DIST_DIR/data/ecosystem-manifest.json" >/dev/null jq -e '.liveSwapRoutes | length >= 19' "$DIST_DIR/data/live-route-registry.json" >/dev/null jq -e '.liveBridgeRoutes | length >= 12' "$DIST_DIR/data/live-route-registry.json" >/dev/null jq -e '.networks[] | select(.chainId == 138) | .venueCounts.deployedVenuePoolCount >= 19 and .summary.totalVenues >= 19' \ "$DIST_DIR/data/deployed-venue-inventory.json" >/dev/null rm -f "$TMP_ARCHIVE" tar -C "$SUBMODULE_ROOT" -czf "$TMP_ARCHIVE" dist scp -q -o StrictHostKeyChecking=accept-new "$TMP_ARCHIVE" "root@$PROXMOX_HOST:/tmp/atomic-swap-dapp-5801.tgz" ssh -o StrictHostKeyChecking=accept-new "root@$PROXMOX_HOST" " pct push $VMID /tmp/atomic-swap-dapp-5801.tgz /tmp/atomic-swap-dapp-5801.tgz pct exec $VMID -- bash -lc ' set -euo pipefail mkdir -p \"$DEPLOY_ROOT\" find \"$DEPLOY_ROOT\" -mindepth 1 -maxdepth 1 -exec rm -rf {} + rm -rf /tmp/dist tar -xzf /tmp/atomic-swap-dapp-5801.tgz -C /tmp cp -R /tmp/dist/. \"$DEPLOY_ROOT/\" mkdir -p /var/cache/nginx/atomic-swap-api cat > /etc/nginx/conf.d/atomic-swap-api-cache.conf <<\"EOF\" proxy_cache_path /var/cache/nginx/atomic-swap-api levels=1:2 keys_zone=atomic_swap_api_cache:10m max_size=256m inactive=30m use_temp_path=off; EOF cat > /etc/nginx/sites-available/atomic-swap <<\"EOF\" server { listen 80 default_server; listen [::]:80 default_server; server_name _; root $DEPLOY_ROOT; index index.html; location / { try_files \$uri \$uri/ /index.html; } location = /index.html { add_header Cache-Control \"no-store, no-cache, must-revalidate\" always; } location /data/ { add_header Cache-Control \"no-store, no-cache, must-revalidate\" always; } location /assets/ { add_header Cache-Control \"public, max-age=31536000, immutable\" always; } location /api/v1/ { proxy_pass https://explorer.d-bis.org/api/v1/; proxy_ssl_server_name on; proxy_set_header Host explorer.d-bis.org; proxy_set_header X-Forwarded-Proto \$scheme; proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Host \$host; proxy_http_version 1.1; proxy_buffering on; proxy_cache atomic_swap_api_cache; proxy_cache_methods GET HEAD; proxy_cache_key \"\$scheme\$proxy_host\$request_uri\"; proxy_cache_lock on; proxy_cache_lock_timeout 10s; proxy_cache_lock_age 10s; proxy_cache_background_update on; proxy_cache_revalidate on; proxy_cache_valid 200 10s; proxy_cache_valid 404 1s; proxy_cache_valid any 0; proxy_cache_use_stale error timeout invalid_header updating http_429 http_500 http_502 http_503 http_504; add_header X-Atomic-Swap-Cache \$upstream_cache_status always; } } EOF ln -sfn /etc/nginx/sites-available/atomic-swap /etc/nginx/sites-enabled/atomic-swap rm -f /etc/nginx/sites-enabled/default rm -f /etc/nginx/sites-enabled/dapp nginx -t systemctl reload nginx curl -fsS http://127.0.0.1/index.html >/dev/null curl -fsS http://127.0.0.1/data/ecosystem-manifest.json >/dev/null curl -fsS http://127.0.0.1/data/live-route-registry.json >/dev/null curl -fsS http://127.0.0.1/data/deployed-venue-inventory.json >/dev/null rm -rf /tmp/dist /tmp/atomic-swap-dapp-5801.tgz ' rm -f /tmp/atomic-swap-dapp-5801.tgz " curl -fsS https://atomic-swap.defi-oracle.io/ >/dev/null curl -fsS https://atomic-swap.defi-oracle.io/data/ecosystem-manifest.json | jq -e '.supportedNetworks[] | select(.chainId == 138) | .deployedVenuePoolCount >= 19 and .publicRoutingPoolCount >= 19' >/dev/null curl -fsS https://atomic-swap.defi-oracle.io/data/live-route-registry.json | jq -e '.liveSwapRoutes | length >= 19' >/dev/null curl -fsS https://atomic-swap.defi-oracle.io/data/live-route-registry.json | jq -e '.liveBridgeRoutes | length >= 12' >/dev/null curl -fsS https://atomic-swap.defi-oracle.io/data/deployed-venue-inventory.json | jq -e '.networks[] | select(.chainId == 138) | .venueCounts.deployedVenuePoolCount >= 19 and .summary.totalVenues >= 19' >/dev/null echo "Deployed atomic-swap-dapp to VMID $VMID via $PROXMOX_HOST"